-
Notifications
You must be signed in to change notification settings - Fork 2
/
routes.coffee
41 lines (30 loc) · 1004 Bytes
/
routes.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
_ = require 'lodash'
Promise = require 'bluebird'
express = require 'express'
log = require 'loglevel'
config = require './config'
router = express.Router()
ConversionCtrl = require './controllers/conversion'
ExperimentCtrl = require './controllers/experiment'
ResultCtrl = require './controllers/result'
HealthCtrl = require './controllers/health'
routes =
'get /healthcheck': HealthCtrl.check
'get /ping': HealthCtrl.ping
'post /experiments': ExperimentCtrl.assign
'get /experiments': ExperimentCtrl.index
'post /experiments/override': ExperimentCtrl.override
'post /conversions': ConversionCtrl.create
'get /conversions': ConversionCtrl.index
'get /results': ResultCtrl.index
_.map routes, (handler, route) ->
verb = route.split(' ')[0]
path = route.split(' ')[1]
router[verb] path, (req, res) ->
Promise.try(handler, [req])
.then (result) ->
res.json result
.catch (err) ->
log.trace err
res.status(500).end null
module.exports = router