]>
git.proxmox.com Git - mirror_xterm.js.git/blob - demo/app.js
1 var express
= require('express');
3 var expressWs
= require('express-ws')(app
);
4 var pty
= require('pty.js');
6 app
.use('/src', express
.static(__dirname
+ '/../src'));
7 app
.use('/addons', express
.static(__dirname
+ '/../addons'));
9 app
.get('/', function(req
, res
){
10 res
.sendFile(__dirname
+ '/index.html');
13 app
.get('/style.css', function(req
, res
){
14 res
.sendFile(__dirname
+ '/style.css');
17 app
.get('/main.js', function(req
, res
){
18 res
.sendFile(__dirname
+ '/main.js');
21 app
.ws('/bash', function(ws
, req
) {
23 * Open bash terminal and attach it
25 var term
= pty
.spawn('bash', [], {
32 term
.on('data', function(data
) {
36 // The WebSocket is not open, ignore
39 ws
.on('message', function(msg
) {
42 ws
.on('close', function () {
44 process
.kill(term
.pid
);
48 var port
= process
.env
.PORT
|| 3000,
51 console
.log('App listening to http://' + host
+ ':' + port
);
52 app
.listen(port
, host
);