-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.coffee
executable file
·48 lines (35 loc) · 1.29 KB
/
index.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
{ spawn } = require 'child_process'
electron = require 'electron'
cssqdConfig = require 'cssqd-config'
path = require 'path'
koa = require 'koa'
serve = require 'koa-static'
mongoose = require 'mongoose'
mongoose.Promise = Promise
appConfig = require './config'
require './config/passport'
Service = require './app/service'
app = do koa
mongohost = cssqdConfig.get 'mongo:host'
mongodb = cssqdConfig.get 'mongo:db'
connectionString = "#{mongohost}/#{mongodb}"
console.log "mongo connection string: #{connectionString}"
console.log "port: #{cssqdConfig.get 'service:port'}"
{connection} = mongoose.connect connectionString
connection.on 'error', console.error.bind console, 'mongoose connection error:'
connection.once 'open', ->
app.use serve path.join __dirname, cssqdConfig.get 'service:static'
appConfig.configureKoa app
appConfig.configureRoutes app
http_server = app.listen cssqdConfig.get 'service:port'
(new Service).start http_server
electron_process = spawn electron, ['./electron'],
stdio:'inherit'
cwd: path.join __dirname, 'app'
process.on 'SIGINT', ->
electron_process.kill()
process.exit()
process.on 'uncaughtException', (err) ->
console.error "#{(new Date).toUTCString()} uncaughtException: #{err.message}"
console.error err.stack
process.exit 1