Skip to content

Instantly share code, notes, and snippets.

@itzaks
Last active December 24, 2015 08:29
Show Gist options
  • Select an option

  • Save itzaks/6770877 to your computer and use it in GitHub Desktop.

Select an option

Save itzaks/6770877 to your computer and use it in GitHub Desktop.
Brunch server file.
class Server
mongoose: require 'mongoose'
express: require 'express'
path = require 'path'
constructor: ->
@app = @express()
@app.use @express.static(path.resolve "public")
@app.use @express.bodyParser()
@configDB()
#start on heroku
@startServer() unless module.parent
configDB: ->
@mongoose.connect process.env.MONGOHQ_URL or 'mongodb://localhost/db-name'
@db = @mongoose.connection
@db.on 'error', console.error.bind(console, 'mongoose error:')
@db.once 'open', -> console.log 'connected to db'
startServer: (port = process.env.PORT, path, callback) ->
console.log "startServer on port: #{ port }, path #{ path }"
@app.listen port
module.exports = new Server()
@itzaks
Copy link
Author

itzaks commented Oct 21, 2013

Then in brunch config.coffee

server:
  path: 'server.coffee'
  port: 1337
  run: yes

:–––––––––––––––––––––)

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