Skip to content

Instantly share code, notes, and snippets.

@morkeleb
Forked from ni-ka/README.md
Last active August 29, 2015 14:13
Show Gist options
  • Save morkeleb/455199f983557a98f36c to your computer and use it in GitHub Desktop.
Save morkeleb/455199f983557a98f36c to your computer and use it in GitHub Desktop.

Usage

  1. Put server.coffee next to config.coffee
  2. Register server.coffee in config.coffee server: path: 'server.coffee'
  3. Add required modules to package.json npm install --save express http-proxy

Notes

  1. Supports reloading environement when bower.json / package.json is changed (returns node server)
express = require 'express'
sysPath = require 'path'
http = require 'http'
httpProxy = require 'http-proxy'
apiProxy = httpProxy.createServer({
target:'http://localhost:3000'
});
exports.startServer = (port, path, callback) ->
app = express();
app.use express.static path
app.all "/api/*", (req, res) ->
delete req.headers.host;
apiProxy.web(req, res)
app.all '/*', (request, response) ->
response.sendfile sysPath.resolve sysPath.join path, 'index.html'
server = http.createServer app
server.listen parseInt(port, 10), callback
server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment