Skip to content

Instantly share code, notes, and snippets.

@PhouvanhKCSV
Forked from gouroujo/proxy.js
Created February 1, 2018 15:08
Show Gist options
  • Save PhouvanhKCSV/084e4f8a062e8e928137f4a1d7c293b2 to your computer and use it in GitHub Desktop.
Save PhouvanhKCSV/084e4f8a062e8e928137f4a1d7c293b2 to your computer and use it in GitHub Desktop.
Proxy on /api for express app using node http-proxy
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