]> git.proxmox.com Git - mirror_xterm.js.git/blame - demo/app.js
Get demo working on Windows
[mirror_xterm.js.git] / demo / app.js
CommitLineData
53e8df40
PK
1var express = require('express');
2var app = express();
3var expressWs = require('express-ws')(app);
4var pty = require('pty.js');
5
6app.use('/src', express.static(__dirname + '/../src'));
7app.use('/addons', express.static(__dirname + '/../addons'));
8
9app.get('/', function(req, res){
10 res.sendFile(__dirname + '/index.html');
11});
12
13app.get('/style.css', function(req, res){
14 res.sendFile(__dirname + '/style.css');
15});
16
17app.get('/main.js', function(req, res){
18 res.sendFile(__dirname + '/main.js');
19});
20
21app.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
48var port = process.env.PORT || 3000,
623853f3 49 host = '127.0.0.1';
53e8df40 50
47b01786 51console.log('App listening to http://' + host + ':' + port);
53e8df40 52app.listen(port, host);