Enable destroying a tty.js tunnel.

This commit is contained in:
Pagan Gazzard 2014-08-15 19:28:04 +01:00 committed by Pablo Carranza Vélez
parent 1b0e364322
commit ad107b30ae
2 changed files with 22 additions and 0 deletions

View File

@ -38,4 +38,15 @@ api.post '/v1/spawn-tty', (req, res) ->
.catch (err) -> .catch (err) ->
res.send(404, err) res.send(404, err)
api.post '/v1/despawn-tty', (req, res) ->
appId = req.body.appId
utils.mixpanelTrack('Despawn tty', appId)
if !appId?
res.send(400, 'Missing app id')
tty.stop(appId)
.then ->
res.send(200)
.catch (err) ->
res.send(404, err)
module.exports = api module.exports = api

View File

@ -23,3 +23,14 @@ exports.start = (appId) ->
.listenAsync(port, null) .listenAsync(port, null)
.then -> .then ->
ngrok.connectAsync(port) ngrok.connectAsync(port)
DISCONNECTED = 'Disconnected'
disconnectedErr = (err) -> return err.message is DISCONNECTED
exports.stop = (appId) ->
if !apps[appId]?
return Promise.resolve()
apps[appId] = apps[appId].then (url) ->
ngrok.disconnectAsync(url)
.then ->
throw new Error(DISCONNECTED)
return apps[appId].catch disconnectedErr, -> # All good!