Skip to content

Instantly share code, notes, and snippets.

@ryands
Created August 4, 2014 21:57
Show Gist options
  • Save ryands/90bbde2af5f5b96dbafd to your computer and use it in GitHub Desktop.
Save ryands/90bbde2af5f5b96dbafd to your computer and use it in GitHub Desktop.
quick node proxy for local XHR proxying
/* 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