Skip to content

Instantly share code, notes, and snippets.

@sandipchitale
Last active July 7, 2018 03:07
Show Gist options
  • Save sandipchitale/b7236c812886a511486414a5ccbbb46f to your computer and use it in GitHub Desktop.
Save sandipchitale/b7236c812886a511486414a5ccbbb46f to your computer and use it in GitHub Desktop.
A simple proxy
var express = require('express');
var app = express();
var httpProxy = require('http-proxy');
var apiProxy = httpProxy.createProxyServer();
var ias = 'http://localhost:8765';
apiProxy.on('proxyReq', function (proxyReq, req, res) {
// console.log('RAW Request headers sent to target:\n', JSON.stringify(proxyReq.getHeaders(), true, 2));
})
app.all("/*", function(req, res) {
apiProxy.web(req, res, {target: ias});
});
app.listen(3000);
{
"name": "proxy",
"version": "1.0.0",
"description": "A simple proxy using express.",
"main": "index.js",
"scripts": {
"start": "node app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Sandip Chitale",
"license": "ISC",
"dependencies": {
"express": "^4.16.3",
"http-proxy": "^1.17.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment