forked from gijs/dashku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.coffee
48 lines (36 loc) · 1.45 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
fs = require 'fs'
http = require 'http'
connectRoute = require 'connect-route'
ss = require 'socketstream'
internals = require './internals'
# 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', ss.api.app.config.redis
# Use redis for pubsub
ss.publish.transport.use 'redis', ss.api.app.config.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. Other engines available
ss.client.templateEngine.use require 'ss-hogan'
ss.ws.transport.use require 'ss-engine.io'
# 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 ss.api.app.config.port
ss.start server
# So that the process never dies
# process.on 'uncaughtException', (err) -> console.error 'Exception caught: ', err