Skip to content

emanuelelongo/no-cors-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

no-cors-proxy

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.

Using as global module

$ 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.
Available options:
  • -h host (default: localhost)
  • -p port (default: 3000)
  • -t target (default: localhost)

Using as local dependency

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"
}

Using programmatically

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();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published