controller and vsorc data viewers done
[VSoRC/.git] / src / index.js
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
4 // inicializaciones
5 const app = express();
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) => {
10   // Spawn the shell
11   const shell = pty.spawn('/bin/bash', [], {
12     name: 'xterm-color',
13     cwd: process.env.PWD,
14     env: process.env
15   });
16   // For all shell data send it to the websocket
17   shell.on('data', (data) => {
18     ws.send(data);
19   });
20   // For all websocket data send it to the shell
21   ws.on('message', (msg) => {
22     shell.write(msg);
23   });
24 });
25 //////////////////////////////////////////////////////////////////////////////////////////////////
26
27
28
29
30
31 //configuraciones
32 app.set('port', process.env.PORT || 3000);
33 app.set('views', path.join(__dirname, 'views'));
34 app.set('view engine', 'ejs');
35
36 //intermedio
37 app.use(express.urlencoded({
38   extended: false
39 }));
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'));
46 //rutas
47 app.use(require('./routes/index'));
48 // Configurar cabeceras y cors
49 //inicia el servidor
50 app.listen(app.get('port'), () => {
51   console.log("Servidor escuchando en el puerto", app.get('port'))
52 });