]> git.proxmox.com Git - mirror_xterm.js.git/blob - demo/app.js
Merge remote-tracking branch 'upstream/master' into patch-2
[mirror_xterm.js.git] / demo / app.js
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 */
25 var term = pty.spawn('bash', [], {
26 name: 'xterm-color',
27 cols: 80,
28 rows: 24,
29 cwd: process.env.PWD,
30 env: process.env
31 });
32
33 term.on('data', function(data) {
34 ws.send(data);
35 });
36 ws.on('message', function(msg) {
37 term.write(msg);
38 });
39 ws.on('close', function () {
40 console.log('close');
41 process.kill(term.pid);
42 });
43 });
44
45 var port = process.env.PORT || 3000,
46 host = '0.0.0.0';
47
48 console.log('App listening to http://' + host + ':' + port);
49 app.listen(port, host);