Create a gist now

Instantly share code, notes, and snippets.

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