-
Notifications
You must be signed in to change notification settings - Fork 84
/
app.coffee
56 lines (43 loc) · 1.86 KB
/
app.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
53
54
55
56
fs = require 'fs'
http = require 'http'
connect = require 'connect'
connectRoute = require 'connect-route'
global.ss = require 'socketstream'
global.uuid = require 'node-uuid'
global._ = require 'underscore'
global.config = require "#{__dirname}/server/config.coffee"
require "#{__dirname}/server/db.coffee"
require "#{__dirname}/server/mailer.coffee"
# Controllers, a way of sharing common logic between RPC and REST APIs
global.dashboardController = require "#{__dirname}/server/controllers/dashboard.coffee"
global.widgetController = require "#{__dirname}/server/controllers/widget.coffee"
# Define a single-page client
ss.client.define 'main',
view: 'app.jade'
css: ['libs', 'app.styl']
code: ['libs', 'app']
tmpl: '*'
api = require "#{__dirname}/server/api.coffee"
ss.http.middleware.prepend ss.http.connect.bodyParser()
ss.http.middleware.prepend ss.http.connect.query()
ss.http.middleware.prepend connectRoute api
# Serve this client on the root URL
ss.http.route '/', (req, res) -> res.serveClient 'main'
# Use redis for session store
ss.session.store.use 'redis', config[ss.env].redis
# Use redis for pubsub
ss.publish.transport.use 'redis', config[ss.env].redis
# Code Formatters
ss.client.formatters.add require 'ss-coffee'
ss.client.formatters.add require 'ss-jade'
ss.client.formatters.add require 'ss-stylus'
# Use server-side compiled Hogan (Mustache) templates. Others engines available
ss.client.templateEngine.use require 'ss-hogan'
# Minimize and pack assets if you type: SS_PACK=1 SS_ENV=production node app.js
ss.client.packAssets() if ss.env is 'production'
# Start SocketStream
server = http.Server ss.http.middleware
server.listen config[ss.env].port
ss.start server
# So that the process never dies
process.on 'uncaughtException', (err) -> console.error 'Exception caught: ', err