Created
July 23, 2015 08:53
-
-
Save juliankrispel/805464a08aa7ca15b96e to your computer and use it in GitHub Desktop.
This file contains 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
var express = require('express'); | |
var app = express(); | |
var request = require('request'); | |
var protocol = 'https'; | |
var port = 5000; | |
var _ = require('lodash'); | |
var path = require('path'); | |
var proxyUrl = 'app.rnfrstqa.com'; | |
var makeUrl = function(url){ | |
return protocol + '://' + path.join(proxyUrl, url); | |
}; | |
var proxyMiddleware = function(req, res, next){ | |
req.url = makeUrl(req.url) | |
req.headers.host = proxyUrl; | |
req.pipe(request(_.pick(req, 'url', 'headers', 'body', 'method'))).pipe(res); | |
}; | |
app.get('/*', proxyMiddleware); | |
var server = app.listen(port, function () { | |
var host = server.address().address; | |
if(host === '::') host = '0.0.0.0' | |
var port = server.address().port; | |
console.log('static-proxy listening at http://%s:%s', host, port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment