Skip to content

Instantly share code, notes, and snippets.

@a-theriault
Created May 28, 2015 23:13
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 a-theriault/f3999392d60bfccf0150 to your computer and use it in GitHub Desktop.
Save a-theriault/f3999392d60bfccf0150 to your computer and use it in GitHub Desktop.
// API requests get redirected to the Roomie Agent API
server.post('/api/*', function(req,res) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
var url = appConfig.BASEURL + req.url.split('/api/')[1];
request.post({url: url, form: JSON.stringify(req.body)},function(err,response,data) {
res.send(data);
});
});
// Everything else loads the API tester on the same port, to get around CORS limitations
server.all('/*', function(req, res) {
res.sendFile('index.html', { root: 'build' });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment