-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.coffee
52 lines (41 loc) · 1.53 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
46
47
48
49
50
51
52
express = require "express"
bodyParser = require "body-parser"
compression = require "compression"
cookieParser = require "cookie-parser"
engines = require "consolidate"
errorHandler = require "errorhandler"
favicon = require "serve-favicon"
similarity = require "./similarity"
exports.startServer = (config, callback) ->
app = express()
# setup views and port
app.set "views", config.server.views.path
app.engine config.server.views.extension, engines[config.server.views.compileWith]
app.set "view engine", config.server.views.extension
app.set "port", process.env.PORT or config.server.port or 3000
# middleware
app.use compression()
# uncomment and point path at favicon if you have one
# app.use favicon "path to fav icon"
app.use bodyParser.json()
app.use bodyParser.urlencoded {extended: true}
app.use cookieParser()
app.use express.static config.watch.compiledDir
if app.get("env") isnt "production"
app.use errorHandler dumpExceptions: on
else
app.use errorHandler()
routeOptions =
reload: config.liveReload.enabled
optimize: config.isOptimize ? false
cachebust: if process.env.NODE_ENV isnt "production" then "?b=#{(new Date()).getTime()}" else ""
router = express.Router()
router.get "/", (req, res) ->
res.render "index", routeOptions
# routes
app.use "/", router
app.post "/similarity", similarity.post
# start it up
server = app.listen app.get("port"), ->
console.log "Express server listening on port " + app.get "port"
callback server