210117_wasm_try

node v10.24.1
version: 0.0.1
endpointsharetweet
const { exec } = require('child_process'); function promExec(cmd){ return new Promise((ok,bad)=>{ exec(cmd, (err, stdo, stde)=>{ const r = ({err, stdo, stde}); // console.log(r); (!!err? bad : ok)(r); }) }).then(e=>e.stdo) .then(s=>s.split('\n').filter(s=>s.length >0) ) .then(console.log) .catch(console.log); } const cmd = [ [ 'git --ve', 'git --version' ],[ "yes | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh", 'echo $PATH' // "PATH=$ ~/.cargo/bin" ] ]; (async _=>{ await promExec(cmd[1][0]) await promExec(cmd[1][1]) })()
const client = [ '<!doctype html>', '<html>', '<head>', '<link rel="stylesheet" href="node_modules/xterm/css/xterm.css" />', '<script src="node_modules/xterm/lib/xterm.js"></script>', '</head>', '<body>', '<div id="terminal"></div>', '<script>', 'var term = new Terminal();', ' term.open(document.getElementById("terminal"));', "term.write('Hello from \x1B[1;3;31mxterm.js\x1B[0m $ ')", "</script>", " </body>", "</html>",].join('');
const pty = require('pty.js'); const WsStream = require('wsstream'); var express = require("@runkit/runkit/express-endpoint/1.0.0"); var app = express(exports); app.get("/", (req, res) => res.send(client)) app.ws('/', (ws, req) => { const stream = WsStream(ws); const bash = pty.spawn('bash'); bash.pipe(stream); stream.pipe(bash); });
Loading…

no comments

    sign in to comment