Created
August 26, 2016 11:33
-
-
Save wenshin/208df80ff761c626d310923f2197072c 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
/** | |
* Usage: | |
* ``` | |
* $ node reverseproxy.js | |
* | |
* ``` | |
* */ | |
const request = require('request'); // https://github.com/request/request | |
const http = require('http'); | |
const PROXY_URL = 'http://your.proxyserver.com'; | |
var TARGET_HOST = 'http://your.domain.com'; | |
console.log(`PROXY: ${PROXY_URL}`); | |
console.log('TARGET_HOST: ', TARGET_HOST); | |
http.createServer((req, res) => { | |
const targetUrl = `http://${TARGET_HOST}${req.url}`; | |
console.log(`[${req.method}]`, targetUrl); | |
const reqProxy = request({url: targetUrl, proxy: PROXY_URL}) | |
.on('error', (e) => console.log(e)); | |
req.pipe(reqProxy).pipe(res); | |
}).listen(SERVER_PORT); | |
console.log('server on 127.0.0.1:' + SERVER_PORT); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment