Last active
August 19, 2019 07:09
-
-
Save Korver2017/465dbd81a866bfb58fae17c6dd79f2fe to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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