From ad429f6c637a179bcad87360998f85141b8811ec Mon Sep 17 00:00:00 2001 From: digital dreamer Date: Fri, 1 Jan 2016 12:47:26 +0100 Subject: [PATCH] Handle the Listen EAccess error --- twister-proxy.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/twister-proxy.js b/twister-proxy.js index 7560bbb..52c5682 100644 --- a/twister-proxy.js +++ b/twister-proxy.js @@ -7,6 +7,15 @@ var console = require("console"); var app = express(); var cors = require('cors'); +function handlePortAccessError() +{ + console.log("Error: Node.js doesn't allow access to ports lower than 1024 in normal user mode."); + console.log(" Possible solutions:"); + console.log(" 1 - Edit settings.json and change \"http_port\": 80 to a higher number. It will then run under any user."); + console.log(" 2 - If you want to use standard HTTP port, run the server as root: sudo node twister-proxy.js &"); + process.exit(1); +} + try { var settings = JSON.parse(fs.readFileSync("settings.json")); @@ -202,11 +211,10 @@ app.post("/", function(request, response) }); if(settings.Server.enable_https) -{ - https.createServer(credentials, app).listen(settings.Server.https_port); -} + https.createServer(credentials, app).listen(settings.Server.https_port).on("error", handlePortAccessError); + +http.createServer(app).listen(settings.Server.http_port).on("error", handlePortAccessError); -http.createServer(app).listen(settings.Server.http_port); setInterval(function() {