Skip to content

Instantly share code, notes, and snippets.

@Korver2017
Last active August 19, 2019 07:09
Show Gist options
  • Select an option

  • Save Korver2017/465dbd81a866bfb58fae17c6dd79f2fe to your computer and use it in GitHub Desktop.

Select an option

Save Korver2017/465dbd81a866bfb58fae17c6dd79f2fe to your computer and use it in GitHub Desktop.
if (req.method === 'OPTIONS') {
// CORS Preflight
res.send();
} else {
// var targetURL = req.header('Target-URL');
var targetURL = req.header('Target-Endpoint');
if (!targetURL) {
res.send(500, { error: 'There is no Target-Endpoint header in the request' });
return;
}
// request({ url: targetURL + req.url, method: req.method, json: req.body, headers: {'Authorization': req.header('Authorization')} },
request({ url: targetURL + req.url, method: req.method, json: req.body, headers: { 'Authorization': req.header('Target-Endpoint') } },
function (error, response, body) {
if (error) {
console.error('error: ' + response.statusCode)
}
// console.log(body);
}).pipe(res);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment