Last active
December 24, 2015 08:29
-
-
Save itzaks/6770877 to your computer and use it in GitHub Desktop.
Brunch server file.
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
| 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() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Then in brunch config.coffee
:–––––––––––––––––––––)