Use the new status/send/sendStatus style.

This commit is contained in:
Pagan Gazzard 2015-03-09 12:06:24 +00:00 committed by Pablo Carranza Vélez
parent 6144ea3aeb
commit d578bbfba3

View File

@ -14,43 +14,43 @@ module.exports = (secret) ->
if req.query.apikey is secret if req.query.apikey is secret
next() next()
else else
res.send(401) res.sendStatus(401)
api.post '/v1/blink', (req, res) -> api.post '/v1/blink', (req, res) ->
utils.mixpanelTrack('Device blink') utils.mixpanelTrack('Device blink')
utils.blink.pattern.start() utils.blink.pattern.start()
setTimeout(utils.blink.pattern.stop, 15000) setTimeout(utils.blink.pattern.stop, 15000)
res.send(200) res.sendStatus(200)
api.post '/v1/update', (req, res) -> api.post '/v1/update', (req, res) ->
utils.mixpanelTrack('Update notification') utils.mixpanelTrack('Update notification')
application.update() application.update()
res.send(204) res.sendStatus(204)
api.post '/v1/spawn-tty', (req, res) -> api.post '/v1/spawn-tty', (req, res) ->
appId = req.body.appId appId = req.body.appId
utils.mixpanelTrack('Spawn tty', appId) utils.mixpanelTrack('Spawn tty', appId)
if !appId? if !appId?
res.send(400, 'Missing app id') res.status(400).send('Missing app id')
knex('app').select().where({appId}) knex('app').select().where({appId})
.then ([ app ]) -> .then ([ app ]) ->
if !app? if !app?
throw new Error('App not found') throw new Error('App not found')
tty.start(app) tty.start(app)
.then (url) -> .then (url) ->
res.send(200, url) res.status(200).send(url)
.catch (err) -> .catch (err) ->
res.send(503, err?.message or err or 'Unknown error') res.status(503).send(err?.message or err or 'Unknown error')
api.post '/v1/despawn-tty', (req, res) -> api.post '/v1/despawn-tty', (req, res) ->
appId = req.body.appId appId = req.body.appId
utils.mixpanelTrack('Despawn tty', appId) utils.mixpanelTrack('Despawn tty', appId)
if !appId? if !appId?
res.send(400, 'Missing app id') res.status(400).send('Missing app id')
tty.stop(appId) tty.stop(appId)
.then -> .then ->
res.send(200) res.sendStatus(200)
.catch (err) -> .catch (err) ->
res.send(503, err?.message or err or 'Unknown error') res.status(503).send(err?.message or err or 'Unknown error')
return api return api