forked from cozy/cozy-contacts-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.coffee
33 lines (26 loc) · 854 Bytes
/
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
americano = require('americano')
Realtimer = require 'cozy-realtime-adapter'
start = (host, port, callback) ->
americano.start
name: 'Contacts'
port: port
root: __dirname
host: host
, (app, server) ->
# Migration scripts
Contact = require './server/models/contact'
Contact.migrateAll ->
# start contact watch to upadte UI when new contact are added
# or modified
realtime = Realtimer server, ['contact.*']
callback? null, app, server
if not module.parent
host = process.env.HOST or '127.0.0.1'
port = process.env.PORT or 9114
start host, port, (err) ->
if err
console.log "Initialization failed, not starting"
console.log err.stack
process.exit 1
else
module.exports = start