diff --git a/index.js b/index.js index 5bd8ec5..5601730 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,8 @@ const express = require("express"); // could be good to replace with c // Get port or default to 8082 const port = process.env.PORT || 8082; const protocol = 'https' -const subclass = '192.168.4.' +// TODO merge from responsive-workspace-demoday +const subclass = '192.168.0.' const publicKeyPath = path.resolve(process.env.HOME,'.ssh','id_rsa_offlineoctopus.pub') const publicKey = fs.readFileSync(publicKeyPath).toString().split(' ')[1] @@ -245,13 +246,13 @@ app.get('/foundpeers', (req, res) => { let foundPeers = [] app.get('/scan', (req, res) => { - scanpeers() - res.json( {msg: 'started'} ) // could redirect('/foundpeers') too after a timeout + scanpeers(res) + //res.json( {msg: 'started'} ) // could redirect('/foundpeers') too after a timeout }) -function scanpeers(){ +function scanpeers(queryres=null){ foundPeers = [] - for (let i=1;i<25;i++){ // async so blasting, gives very quick result for positives + for (let i=1;i<254;i++){ // async so blasting, gives very quick result for positives let url=protocol+'://'+subclass+i+':'+port+'/available' let opt={rejectUnauthorized: false} https.get(url, opt, res => { @@ -268,6 +269,8 @@ function scanpeers(){ //console.log(err.message); usually ECONNREFUSED or EHOSTUNREACH }).end() } + if (queryres) setTimeout( _ => queryres.json( foundPeers), 1000 ) + // timing heuristic } app.get('/sshconfig', (req, res) => { @@ -381,3 +384,12 @@ const webServer = https.createServer(credentials, app); webServer.listen(port, () => { console.log("listening on "+protocol+"://localhost:" + port); }); + +const { createProxyMiddleware } = require('http-proxy-middleware'); +app.use( + '/proxied', + createProxyMiddleware({ + target: 'http://localhost:8080', + pathRewrite: { '^/proxied' : ''}, + }) +)