Skip to content

Instantly share code, notes, and snippets.

@rauluranga
Created March 7, 2014 19:34
Show Gist options
  • Save rauluranga/9418261 to your computer and use it in GitHub Desktop.
Save rauluranga/9418261 to your computer and use it in GitHub Desktop.
Custom Brunch server with proxy support
express = require 'express'
sysPath = require 'path'
httpProxy = require 'http-proxy';
request = require 'request';
apiProxy = httpProxy.createServer({
target:'http://localhost:3000'
});
exports.startServer = (port, path, callback) ->
app = express();
app.configure (() ->
app.use express.static path
app.use express.bodyParser();
app.use express.errorHandler());
app.all "/api/*", (req, res) ->
apiProxy.web(req, res)
# sample call using request module
# app.all "/api/*", (req, res) ->
# remote = request 'http://localhost:3000' + req.url;
# req.pipe remote;
# remote.pipe res;
app.all '/*', (request, response) ->
response.sendfile sysPath.resolve sysPath.join path, 'index.html'
app.listen parseInt port, 10
app.on 'listening', callback
app
@ni-ka
Copy link

ni-ka commented Jul 17, 2014

See https://gist.github.com/ni-ka/095511910d54edcdcc47 for an updated version which supports watcher reload (when changing bower.json / package.json)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment