Skip to content

Instantly share code, notes, and snippets.

@Mas-Tool
Created September 2, 2016 22:23
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 Mas-Tool/ef5913f2c6302ee1337a505c7cc79b0d to your computer and use it in GitHub Desktop.
Save Mas-Tool/ef5913f2c6302ee1337a505c7cc79b0d to your computer and use it in GitHub Desktop.
var hoxy = require('hoxy');
var port = 8000;
var proxy = hoxy.createServer().listen(port, function() {
console.log('The proxy is listening on port ' + port + '.');
});
proxy.intercept('response', function(req, resp, cycle) {
if(req.method=="OPTIONS"){
resp.statusCode=200;
var headers = resp.headers;
// IE8 does not allow domains to be specified, just the *
// headers["Access-Control-Allow-Origin"] = req.headers.origin;
headers["access-control-allow-origin"] = "*";
headers["access-control-allow-methods"] = "POST, GET, PUT, DELETE, OPTIONS";
headers["allow"] = "POST, GET, PUT, DELETE, OPTIONS";
headers["access-control-allow-credentials"] = true;
headers["access-control-max-age"] = '86400'; // 24 hours
headers["access-control-allow-headers"] = "X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept,If-Modified-Since,Pragma,Cache-Control";
delete headers.location
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment