1 const express = require('express'); // pide express sea requerido
2 const path = require('path'); // pide que path sea requerido
3 const pty = require('node-pty'); ////////////////ASKS FOR NODE-PTY
6 const expressWs = require('express-ws')(app);///////////////////ASK FOR THE WEBSOCKET FROM EXPRESS
7 //////////////////////////////////////////////////////////////////////////////////////////////////
8 // Instantiate shell and set up data handlers
9 expressWs.app.ws('/shell', (ws, req) => {
11 const shell = pty.spawn('/bin/bash', [], {
16 // For all shell data send it to the websocket
17 shell.on('data', (data) => {
20 // For all websocket data send it to the shell
21 ws.on('message', (msg) => {
25 //////////////////////////////////////////////////////////////////////////////////////////////////
32 app.set('port', process.env.PORT || 3000);
33 app.set('views', path.join(__dirname, 'views'));
34 app.set('view engine', 'ejs');
37 app.use(express.urlencoded({
40 app.use(express.json());
41 //para que la ruta de estilos y js sea visible
42 app.use('/styles', express.static('styles'));
43 app.use('/js', express.static('js'));
44 app.use('/img', express.static('img'));
45 app.use('/node_modules', express.static('node_modules'));
47 app.use(require('./routes/index'));
48 // Configurar cabeceras y cors
50 app.listen(app.get('port'), () => {
51 console.log("Servidor escuchando en el puerto", app.get('port'))