]>
Commit | Line | Data |
---|---|---|
53e8df40 PK |
1 | var express = require('express'); |
2 | var app = express(); | |
3 | var expressWs = require('express-ws')(app); | |
15cf76c7 | 4 | var os = require('os'); |
53e8df40 PK |
5 | var pty = require('pty.js'); |
6 | ||
7 | app.use('/src', express.static(__dirname + '/../src')); | |
8 | app.use('/addons', express.static(__dirname + '/../addons')); | |
9 | ||
10 | app.get('/', function(req, res){ | |
11 | res.sendFile(__dirname + '/index.html'); | |
12 | }); | |
13 | ||
14 | app.get('/style.css', function(req, res){ | |
15 | res.sendFile(__dirname + '/style.css'); | |
16 | }); | |
17 | ||
18 | app.get('/main.js', function(req, res){ | |
19 | res.sendFile(__dirname + '/main.js'); | |
20 | }); | |
21 | ||
22 | app.ws('/bash', function(ws, req) { | |
23 | /** | |
24 | * Open bash terminal and attach it | |
25 | */ | |
623853f3 | 26 | var term = pty.spawn(process.platform === 'win32' ? 'cmd.exe' : 'bash', [], { |
53e8df40 PK |
27 | name: 'xterm-color', |
28 | cols: 80, | |
29 | rows: 24, | |
30 | cwd: process.env.PWD, | |
31 | env: process.env | |
32 | }); | |
53e8df40 | 33 | term.on('data', function(data) { |
7a80efd8 DI |
34 | try { |
35 | ws.send(data); | |
36 | } catch (ex) { | |
37 | // The WebSocket is not open, ignore | |
38 | } | |
53e8df40 PK |
39 | }); |
40 | ws.on('message', function(msg) { | |
41 | term.write(msg); | |
42 | }); | |
43 | ws.on('close', function () { | |
44 | console.log('close'); | |
45 | process.kill(term.pid); | |
46 | }); | |
47 | }); | |
48 | ||
49 | var port = process.env.PORT || 3000, | |
15cf76c7 | 50 | host = os.platform() === 'win32' ? '127.0.0.1' : '0.0.0.0'; |
53e8df40 | 51 | |
47b01786 | 52 | console.log('App listening to http://' + host + ':' + port); |
53e8df40 | 53 | app.listen(port, host); |