Created
August 4, 2014 21:57
-
-
Save ryands/90bbde2af5f5b96dbafd to your computer and use it in GitHub Desktop.
quick node proxy for local XHR proxying
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
/* Local proxy for XHR testing | |
* | |
* Prereq: npm install express request lodash | |
* Running: node proxy.js | |
* | |
*/ | |
// Configuration: | |
var port = 3001; | |
var mapping = { | |
'/data.xml': 'http://example.com/data.xml', | |
'/other.xml': 'http://example.com/other.xml', | |
// .. add these as needed .. | |
} | |
// Dependencies (don't change) | |
var _ = require('lodash'), | |
request = require('request'), | |
express = require('express'); | |
var app = express(); | |
_.forEach(mapping, function (remote, route) { | |
console.log('mapped ', route, '->', remote); | |
app.get(route, function (req, res) { | |
console.log('[GET]', route); | |
request.get(remote).pipe(res); | |
}); | |
}) | |
app.listen(port, function () { | |
console.log('Server started!') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment