X-Git-Url: https://git.josue.xyz/?p=VSoRC%2F.git;a=blobdiff_plain;f=src%2Findex.js;fp=src%2Findex.js;h=82abb7565715783a1dd2ccef41d4965557cfef01;hp=e231888305ea033abbb49f688d344db78c84f9f5;hb=2b1de44527123fab80901384e0f374367500ced8;hpb=e79e4a5a87f3e84f7c1777f10a954453a69bf540 diff --git a/src/index.js b/src/index.js index e231888..82abb75 100644 --- a/src/index.js +++ b/src/index.js @@ -1,8 +1,32 @@ const express = require('express'); // pide express sea requerido const path = require('path'); // pide que path sea requerido - +const pty = require('node-pty'); ////////////////ASKS FOR NODE-PTY // inicializaciones const app = express(); +const expressWs = require('express-ws')(app);///////////////////ASK FOR THE WEBSOCKET FROM EXPRESS +////////////////////////////////////////////////////////////////////////////////////////////////// +// Instantiate shell and set up data handlers +expressWs.app.ws('/shell', (ws, req) => { + // Spawn the shell + const shell = pty.spawn('/bin/bash', [], { + name: 'xterm-color', + cwd: process.env.PWD, + env: process.env + }); + // For all shell data send it to the websocket + shell.on('data', (data) => { + ws.send(data); + }); + // For all websocket data send it to the shell + ws.on('message', (msg) => { + shell.write(msg); + }); +}); +////////////////////////////////////////////////////////////////////////////////////////////////// + + + + //configuraciones app.set('port', process.env.PORT || 3000);