-
-
Save parkerproject/36d6d717e5b524553b8befc3dbdf4b2e to your computer and use it in GitHub Desktop.
Proxy on /api for express app using node http-proxy
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
| import { createProxyServer } from 'http-proxy'; | |
| import url from 'url'; | |
| import _ from 'lodash'; | |
| module.exports = app => { | |
| const proxy = createProxyServer(); | |
| app.all('/api/v1/*', (req, res) => { | |
| const path = _.drop(req.url.split('/'), 3); | |
| proxy.proxyRequest(req, res, { | |
| target: url.resolve('YOUR URL', path.join('/')), | |
| ignorePath: true, | |
| headers: { | |
| 'Authorization': 'XXX)', | |
| }, | |
| }); | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment