Skip to content

Instantly share code, notes, and snippets.

@igorwwwwwwwwwwwwwwwwwwww
Created November 30, 2015 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorwwwwwwwwwwwwwwwwwwww/27c3201346365edd0ee6 to your computer and use it in GitHub Desktop.
Save igorwwwwwwwwwwwwwwwwwwww/27c3201346365edd0ee6 to your computer and use it in GitHub Desktop.
node cors proxy
{
"dependencies": {
"http-proxy": "^1.12.0"
}
}
var httpProxy = require('http-proxy');
var proxy = httpProxy.createProxyServer({ target: 'http://some-host:9999' });
proxy.on('proxyReq', function (proxyReq, req, res, options) {
proxyReq.setHeader('host', options.target.host);
});
proxy.on('proxyRes', function (proxyRes, req, res) {
res.setHeader('Access-Control-Allow-Origin', '*');
});
proxy.listen(1234);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment