Cors

From bibbleWiki
Jump to navigation Jump to search

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

Cors request headers.png

Response Headers

Cors response headers.png