Skip to content

Instantly share code, notes, and snippets.

@unrealsolver
Created August 31, 2014 20:54
Show Gist options
  • Save unrealsolver/20687f17fbf8dbb18522 to your computer and use it in GitHub Desktop.
Save unrealsolver/20687f17fbf8dbb18522 to your computer and use it in GitHub Desktop.
Proxy backend wirh nodejs and expressjs
var express = require('express')
var pipe = require('pipe')
var request = require('request')
var app = express();
// Remote host API root url
var API = 'http://10.9.210.28:8081/hackathon'
app.listen(9000)
// Local api url
app.use('/api', function(req, res){
var url = API + req.url
console.log('Proxying: ' + url)
req.pipe(request(url)).pipe(res)
})
// Static routing
app.all('/*', function(req, res){
var url = __dirname + '/app' + req.url
console.log('Serving url: ' + url)
res.sendFile(url)
})
console.log('Listening...')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment