Created
March 7, 2014 19:34
-
-
Save rauluranga/9418261 to your computer and use it in GitHub Desktop.
Custom Brunch server with proxy support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://gist.github.com/ni-ka/095511910d54edcdcc47 for an updated version which supports watcher reload (when changing bower.json / package.json)