diff options
-rw-r--r-- | websockets/package.json | 2 | ||||
-rwxr-xr-x | websockets/server_proxy.js (renamed from websockets/server.js) | 34 |
2 files changed, 22 insertions, 14 deletions
diff --git a/websockets/package.json b/websockets/package.json index a92d034..7d6d802 100644 --- a/websockets/package.json +++ b/websockets/package.json @@ -2,7 +2,7 @@ "name": "tomsg-webserver", "version": "0.1.0", "description": "tomsg websocket-to-tcp converter", - "main": "server.js", + "main": "server_proxy.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/websockets/server.js b/websockets/server_proxy.js index 763b343..5f4ea17 100755 --- a/websockets/server.js +++ b/websockets/server_proxy.js @@ -4,26 +4,34 @@ const net=require("net"); const https=require("https"); const WebSocket=require("uWebSockets.js"); -const PORT=29546; +let listenport=null; -const upstream={ - host: "localhost", - port: 29536 -}; +let upstream=null; + +function parseUpstream(arg){ + const [host, port]=arg.split(":"); + return {host, port}; +} let httpsConfig=null; -if(process.argv.length==4){ +if(process.argv.length==6){ + upstream=parseUpstream(process.argv[2]); + listenport=+process.argv[3]; console.log("Reading keys for https"); httpsConfig={ - key_file_name: process.argv[2], - cert_file_name: process.argv[3], + key_file_name: process.argv[4], + cert_file_name: process.argv[5], }; -} else if(process.argv.length==2){ +} else if(process.argv.length==4){ + upstream=parseUpstream(process.argv[2]); + listenport=+process.argv[3]; console.log("WARNING: Running without SSL!"); } else { - console.error("Usage: ./server.js # proxy without SSL"); - console.error(" ./server.js <key.pem> <cert.pem> # proxy with SSL"); + console.error("Usage: ./server.js <host:port> <port> # proxy without SSL"); + console.error(" ./server.js <host:port> <port> <key.pem> <cert.pem> # proxy with SSL"); + console.error("'<host:port>' indicates the plain-tcp tomsg server to proxy to."); + console.error("'<port>' indicates the port to listen for websocket connections on."); process.exit(1); } @@ -88,8 +96,8 @@ wsServer=wsServer.ws("/*",{ } }); -wsServer=wsServer.listen(PORT,listenSocket=>{ +wsServer=wsServer.listen(listenport,listenSocket=>{ if(listenSocket){ - console.log(`Websocket server${httpsConfig?" (SSL)":""} bound on port ${PORT}`); + console.log(`Websocket server${httpsConfig?" (SSL)":""} bound on port ${listenport}`); } }); |