forked from geordanr/pacenotes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.coffee
More file actions
47 lines (37 loc) · 1.3 KB
/
Copy pathserver.coffee
File metadata and controls
47 lines (37 loc) · 1.3 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
express = require 'express'
pacenotes = require './lib/pacenotes'
app = express()
app.configure () ->
app.set 'view engine', 'jade'
app.configure 'development', () ->
app.set 'port', 3000
app.configure 'production', () ->
app.set 'port', process.env.PORT ? 80
app.use (req, res, next) ->
console.log "#{new Date().toUTCString()} #{req.ip} #{req.method} #{req.path}"
next()
app.use express.compress()
app.use express.static(__dirname + '/public')
app.use (req, res, next) ->
res.locals.origin = req.query.origin ? null
res.locals.destination = req.query.destination ? null
next()
app.get '/', (req, res) ->
if 'origin' of req.query and 'destination' of req.query
res.locals.origin = req.query.origin
res.locals.destination = req.query.destination
try
pacenotes.paceNotes req.query.origin, req.query.destination, (result) ->
res.locals.leg = result.data
res.locals.error = result.error
res.render 'index'
catch err
res.locals.leg = null
res.locals.error = err
res.render 'index'
else
res.locals.origin = ''
res.locals.destination = ''
res.render 'index'
app.listen app.get('port')
console.log "Listening on port #{app.get 'port'}..."