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