A simple http proxy that add cors header to server responses. Useful if you need to consume an API that doesn't allow cross origin requests.
$ npm install no-cors-proxy -g
$ no-cors-proxy -p 8000 -t http://some.api.com
After executing this command:
- Each request to localhost on port 8000 will be forwarded to some.api.com on port 80
- Responses from server will be provided with Access-Control-Allow-Origin: * http header
- Each OPTIONS request (see: preflight request) will be replyed automatically by the proxy.
- -h host (default: localhost)
- -p port (default: 3000)
- -t target (default: localhost)
npm install no-cors-proxy --save
Then in your package.json launch the proxy before to start your app
"scripts": {
"start": "node ./node_modules/no-cors-proxy/bin -t https://some.api.com | node my-app.js"
}
npm install no-cors-proxy --save
const NoCorsProxy = require('no-cors-proxy');
const port = 8080;
const host = 'localhost';
const target = 'http://some.api.com';
const proxy = new NoCorsProxy(port, host, target)
proxy.start();