Skip to content

Instantly share code, notes, and snippets.

@nkint
Created January 13, 2016 15:48
Show Gist options
  • Save nkint/c7f4828149bb2bf2d2e1 to your computer and use it in GitHub Desktop.
Save nkint/c7f4828149bb2bf2d2e1 to your computer and use it in GitHub Desktop.
node.js proxy cors
// from https://github.com/dbertella/cheap-flights/blob/master/proxy/server.js
var http = require('http'),
httpProxy = require('http-proxy');
var port = 3000;
var proxy = httpProxy.createProxyServer();
http.createServer(function(req, res) {
req.headers.host = 'ryanair-test.herokuapp.com';
res.setHeader("x-lt-header", "YEAH!");
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
proxy.web(req, res, { target: 'http://ryanair-test.herokuapp.com' });
}).listen(port, function() {
console.log('Server started at', port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment