mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-24 15:56:40 +00:00
Enable destroying a tty.js tunnel.
This commit is contained in:
parent
1b0e364322
commit
ad107b30ae
@ -38,4 +38,15 @@ api.post '/v1/spawn-tty', (req, res) ->
|
||||
.catch (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
|
||||
|
@ -23,3 +23,14 @@ exports.start = (appId) ->
|
||||
.listenAsync(port, null)
|
||||
.then ->
|
||||
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!
|
||||
|
Loading…
Reference in New Issue
Block a user