Created
November 30, 2015 10:47
-
-
Save igorwwwwwwwwwwwwwwwwwwww/27c3201346365edd0ee6 to your computer and use it in GitHub Desktop.
node cors proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"http-proxy": "^1.12.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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