-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.coffee
More file actions
52 lines (37 loc) · 1.15 KB
/
app.coffee
File metadata and controls
52 lines (37 loc) · 1.15 KB
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
ApiServer = require 'apiserver'
config = require 'config'
apiserver = new ApiServer()
port = process.env.PORT || config.port
apiserver.listen port, onListen
console.log "API server listening on port #{port} in #{process.env.NODE_ENV} mode"
onListen = (err) ->
if err
console.error "Something terrible happened: #{err.message}"
else
console.log "Successfully bound to port #{@port}"
setTimeout apiserver.close onClose, 5000
onClose = () -> console.log "port unbound correctly"
HelloModule =
world: (req, resp) ->
resp.serveJSON 'Hello, world!'
apiserver.addModule 'v1', 'hello', HelloModule
sendMessage = (destination, message) ->
# TODO
getOriginator = (details) ->
# TODO
getDestination = (details) ->
# TODO
sendErrorResponse = (from, error) ->
# TODO
getForwardedMessage = (details, from, to) ->
# TODO
updateTimestamps = (arr) ->
# TODO
onMessageRecieved = (details) ->
from = getOriginator(details)
to = getDestination(details)
if to == null
sendErrorResponse(from, 'no destination: use a hastag like #secondfriend')
return
sendMessage(to, getForwardedMessage(details, from, to))
updateTimestamps([from, to])