]>
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 os
= require('os');
5 var pty
= require('pty.js');
7 app
.use('/src', express
.static(__dirname
+ '/../src'));
8 app
.use('/addons', express
.static(__dirname
+ '/../addons'));
10 app
.get('/', function(req
, res
){
11 res
.sendFile(__dirname
+ '/index.html');
14 app
.get('/style.css', function(req
, res
){
15 res
.sendFile(__dirname
+ '/style.css');
18 app
.get('/main.js', function(req
, res
){
19 res
.sendFile(__dirname
+ '/main.js');
22 app
.ws('/bash', function(ws
, req
) {
24 * Open bash terminal and attach it
26 var term
= pty
.spawn(process
.platform
=== 'win32' ? 'cmd.exe' : 'bash', [], {
33 term
.on('data', function(data
) {
37 // The WebSocket is not open, ignore
40 ws
.on('message', function(msg
) {
43 ws
.on('close', function () {
45 process
.kill(term
.pid
);
49 var port
= process
.env
.PORT
|| 3000,
50 host
= os
.platform() === 'win32' ? '127.0.0.1' : '0.0.0.0';
52 console
.log('App listening to http://' + host
+ ':' + port
);
53 app
.listen(port
, host
);