Cors: Difference between revisions

From bibbleWiki
Jump to navigation Jump to search
Created page with " Sample packages.json <syntaxhighlight lang="json"> { "name": "project1", "version": "1.0.0", "description": "", "main": "src/index.js", "scripts": { "start": "b..."
 
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
Rending resource from another domain cause CORS errors. E.g. playing an mp3. To get around this you need to add a proxy to your package.json. For example if the local PC is 192.168.1.10 (domain1.local) and the resources are on 192.168.1.11 (domain2.local) just add
<syntaxhighlight lang="json">
"proxy": "http://192.168.1.11",
</syntaxhighlight>
All request for / or /Images or any other resource under / will be redirected to 192.168.1.2


Sample packages.json
Sample packages.json
Line 11: Line 19:
     "debug": "babel-node debug src/index.js"
     "debug": "babel-node debug src/index.js"
   },
   },
  "proxy": "http://192.168.1.11",
   "author": "",
   "author": "",
   "license": "ISC",
   "license": "ISC",
Line 28: Line 37:
}
}
</syntaxhighlight>
</syntaxhighlight>
=CORS Headers=
==Request Headers==
[[file:cors request headers.png]]
==Response Headers==
[[file:cors response headers.png]]

Latest revision as of 20:47, 19 October 2020

Rending resource from another domain cause CORS errors. E.g. playing an mp3. To get around this you need to add a proxy to your package.json. For example if the local PC is 192.168.1.10 (domain1.local) and the resources are on 192.168.1.11 (domain2.local) just add

"proxy": "http://192.168.1.11",

All request for / or /Images or any other resource under / will be redirected to 192.168.1.2

Sample packages.json

{
  "name": "project1",
  "version": "1.0.0",
  "description": "",
  "main": "src/index.js",
  "scripts": {
    "start": "babel-node src/index.js",
    "debug": "babel-node debug src/index.js"
  },
  "proxy": "http://192.168.1.11",
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/cli": "^7.6.4",
    "@babel/core": "^7.6.4",
    "@babel/preset-env": "^7.6.3",
    "babel-core": "^7.0.0-bridge.0"
  },
  "dependencies": {
    "@babel/node": "^7.6.3",
    "@babel/preset-env": "^7.6.3",
    "babel-register": "^6.26.0",
    "express": "^4.17.1",
    "nodemon": "^1.19.4"
  }
}

CORS Headers

Request Headers

Response Headers