2013-12-23 04:22:54 +00:00
|
|
|
Promise = require 'bluebird'
|
|
|
|
fs = Promise.promisifyAll require 'fs'
|
|
|
|
utils = require './utils'
|
2013-12-14 05:18:20 +00:00
|
|
|
express = require 'express'
|
2013-12-29 18:07:58 +00:00
|
|
|
application = require './application'
|
2014-06-06 21:46:23 +00:00
|
|
|
supervisor = require './supervisor-update'
|
2014-08-04 11:10:36 +00:00
|
|
|
tty = require './tty'
|
2013-12-14 05:18:20 +00:00
|
|
|
|
|
|
|
api = express()
|
2014-08-04 11:10:36 +00:00
|
|
|
api.use(express.bodyParser())
|
2013-12-14 05:18:20 +00:00
|
|
|
|
2014-03-19 19:54:39 +00:00
|
|
|
api.post '/v1/blink', (req, res) ->
|
2014-06-18 16:54:36 +00:00
|
|
|
utils.mixpanelTrack('Device blink')
|
2014-08-14 21:32:03 +00:00
|
|
|
interval = setInterval(utils.blink, 400)
|
2013-12-17 06:04:53 +00:00
|
|
|
setTimeout(->
|
|
|
|
clearInterval(interval)
|
2014-04-27 21:22:06 +00:00
|
|
|
, 15000)
|
2013-12-14 05:18:20 +00:00
|
|
|
res.send(200)
|
|
|
|
|
2014-03-19 19:54:39 +00:00
|
|
|
api.post '/v1/update', (req, res) ->
|
2014-06-18 16:54:36 +00:00
|
|
|
utils.mixpanelTrack('Update notification')
|
2013-12-29 18:07:58 +00:00
|
|
|
application.update()
|
2013-12-23 04:31:33 +00:00
|
|
|
res.send(204)
|
2013-12-14 05:18:20 +00:00
|
|
|
|
2014-06-06 21:46:23 +00:00
|
|
|
api.post '/v1/update-supervisor', (req, res) ->
|
|
|
|
console.log('Got supervisor update')
|
|
|
|
supervisor.update()
|
|
|
|
res.send(204)
|
|
|
|
|
2014-08-04 11:10:36 +00:00
|
|
|
api.post '/v1/spawn-tty', (req, res) ->
|
|
|
|
appId = req.body.appId
|
|
|
|
utils.mixpanelTrack('Spawn tty', appId)
|
|
|
|
if !appId?
|
|
|
|
res.send(400, 'Missing app id')
|
|
|
|
tty.start(appId)
|
|
|
|
.then (url) ->
|
|
|
|
res.send(200, url)
|
|
|
|
.catch (err) ->
|
|
|
|
res.send(404, err)
|
|
|
|
|
2013-12-14 05:18:20 +00:00
|
|
|
module.exports = api
|