Skip to content

Instantly share code, notes, and snippets.

@Anks
Created August 20, 2012 08:32
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Anks/3402241 to your computer and use it in GitHub Desktop.
Save Anks/3402241 to your computer and use it in GitHub Desktop.
Easy local development with a node.js proxy
{
"name": "your-app-name",
"version": "0.0.1",
"private": true,
"dependencies": {
"http-proxy": "0.8.x",
"connect": "2.3.x"
}
}
var httpProxy = require('http-proxy'),
connect = require('connect'),
endpoint = {
host: 'your-app-domain.com', // or IP address
port: 80,
prefix: '/api'
},
staticDir = 'public';
var proxy = new httpProxy.RoutingProxy();
var app = connect()
.use(connect.logger('dev'))
.use(function(req, res) {
if (req.url.indexOf(endpoint.prefix) === 0) {
proxy.proxyRequest(req, res, endpoint);
}
})
.use(connect.static(staticDir))
.listen(4242);
// http://localhost:4242/api/test will give response
// from http://your-app-domain.com/api/test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment