-
Notifications
You must be signed in to change notification settings - Fork 11
/
server.coffee
executable file
·45 lines (34 loc) · 1.04 KB
/
server.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Module dependencies.
express = require('express')
fs = require('fs')
stylus = require('stylus')
# Main application entry file.
# Please note that the order of loading is important.
# Load configurations
# if test env, load example file
env = process.env.NODE_ENV = process.env.NODE_ENV or 'development'
config = require './config/config'
mongoose = require 'mongoose'
# Bootstrap db connection
db = mongoose.connect(config.db)
# Bootstrap models
models_path = __dirname + '/server/models'
walk = (path) ->
fs.readdirSync(path).forEach (file) ->
newPath = path + '/' + file
stat = fs.statSync(newPath)
if stat.isFile()
require newPath if /(.*)\.(js|coffee)/.test(file)
else walk newPath if stat.isDirectory()
walk models_path
app = express()
#express settings
require('./config/express')(app, db)
#Bootstrap routes
require('./config/routes')(app)
#Start the app by listening on <port>
port = process.env.PORT or config.port
app.listen port
console.log 'Express app started on port ' + port
#expose app
exports = module.exports = app