Separate out tty.js

This commit is contained in:
Pagan Gazzard 2014-12-22 20:12:38 +00:00 committed by Pablo Carranza Vélez
parent 0b93c1ce2c
commit f0afcb706a
5 changed files with 20 additions and 20 deletions

View File

@ -3,7 +3,6 @@ set -o pipefail
if [ $NODE_ENV == 'production' ]; then
chmod +x src/enterContainer.sh
cp ttyjs-static/* node_modules/tty.js/static/
node ./node_modules/coffee-script/bin/coffee -c ./src
# We don't need coffee-script at runtime

View File

@ -4,7 +4,8 @@ utils = require './utils'
express = require 'express'
application = require './application'
supervisor = require './supervisor-update'
tty = require './tty'
tty = require './lib/tty'
knex = require './db'
api = express()
api.use(express.bodyParser())
@ -30,7 +31,11 @@ api.post '/v1/spawn-tty', (req, res) ->
utils.mixpanelTrack('Spawn tty', appId)
if !appId?
res.send(400, 'Missing app id')
tty.start(appId)
knex('app').select().where({appId})
.then ([ app ]) ->
if !app?
throw new Error('App not found')
tty.start(app)
.then (url) ->
res.send(200, url)
.catch (err) ->

View File

@ -9,7 +9,7 @@ PUBNUB = require 'pubnub'
Promise = require 'bluebird'
PlatformAPI = require 'resin-platform-api/request'
utils = require './utils'
tty = require './tty'
tty = require './lib/tty'
{docker} = dockerUtils

View File

@ -1,7 +1,6 @@
Promise = require 'bluebird'
ngrok = Promise.promisifyAll require 'ngrok'
tty = Promise.promisifyAll require 'tty.js'
knex = require './db'
TypedError = require 'typed-error'
class DisconnectedError extends TypedError
@ -10,22 +9,19 @@ class DisconnectedError extends TypedError
apps = {}
nextPort = 81
exports.start = (appId) ->
apps[appId] ?= Promise.rejected()
return apps[appId] = apps[appId].catch ->
exports.start = (app) ->
apps[app.id] ?= Promise.rejected()
return apps[app.id] = apps[app.id].catch ->
port = nextPort++
knex('app').select().where({appId})
.then ([ app ]) ->
if !app?
throw new Error('App not found')
tty.createServer
shell: './src/enterContainer.sh'
shellArgs: do ->
i = 0
return (session) -> [ app.containerId, session.id, i++ ]
.listenAsync(port, null)
.then ->
ngrok.connectAsync(port)
tty.createServer
shell: './src/enterContainer.sh'
shellArgs: do ->
i = 0
return (session) -> [ app.containerId, session.id, i++ ]
static: __dirname + '/static'
.listenAsync(port, null)
.then ->
ngrok.connectAsync(port)
exports.stop = (appId) ->
if !apps[appId]?