Skip to content

Instantly share code, notes, and snippets.

@amir20
Created February 28, 2012 21:34
Show Gist options
  • Save amir20/1935306 to your computer and use it in GitHub Desktop.
Save amir20/1935306 to your computer and use it in GitHub Desktop.
A rails proxy written in node.js for testing assets. No need for apache.
{
"name": "rails-proxy",
"version": "0.0.1",
"dependencies": {
"http-proxy": "*",
"node-static": "*"
},
"engines": { "node": ">= 0.4.4" }
}
var httpProxy = require('http-proxy')
, static = require('node-static')
var file = new(static.Server)('./public/assets');
require('http').createServer(function (request, response) {
request.addListener('end', function () {
console.log("Fetching /assets/" + request.url);
file.serve(request, response);
});
}).listen(7000);
console.log("Starting asset static server on port 7000");
var options = {
router: {
'localhost/assets': '0.0.0.0:7000',
'localhost': '0.0.0.0:3000'
}
};
var proxyServer = httpProxy.createServer(options).listen(8080);
console.log("Listening on port 8080 and forwarding all requests to 0.0.0.0:3000");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment