From bcbfeed1516eac37cae957880b7b00d256a3f1f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Mon, 5 Feb 2018 20:19:09 +0100 Subject: [PATCH 1/3] No more redirecting --- server/routing/client/router.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/routing/client/router.js b/server/routing/client/router.js index 33987d91..142c0ebe 100644 --- a/server/routing/client/router.js +++ b/server/routing/client/router.js @@ -46,7 +46,7 @@ function root(req, res, next) { try{ var url = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'] : req.headers.host.split(":")[0]; var subdomain = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'].split(".") : req.headers.host.split(":")[0].split("."); - if(url != "zoff.me" && url != "remote.zoff.me" && url != "fb.zoff.me" && url != "remote.localhost" && url != "localhost") { + if(url != "zoff.me" && url != "admin.zoff.me" && url != "remote.zoff.me" && url != "fb.zoff.me" && url != "remote.localhost" && url != "localhost") { res.redirect("https://zoff.me"); return; } @@ -77,7 +77,7 @@ function channel(req, res, next) { try{ var url = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'] : req.headers.host.split(":")[0]; var subdomain = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'].split(".") : req.headers.host.split(":")[0].split("."); - if(url != "zoff.me" && url != "remote.zoff.me" && url != "fb.zoff.me" && url != "remote.localhost" && url != "localhost") { + if(url != "zoff.me" && url != "admin.zoff.me" && url != "remote.zoff.me" && url != "fb.zoff.me" && url != "remote.localhost" && url != "localhost") { res.redirect("https://zoff.me"); return; } From 2645a9b9dcc6812b003d47ff954d9c1d1ed38a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Mon, 5 Feb 2018 20:21:00 +0100 Subject: [PATCH 2/3] Trying a fix for adminpanelserver --- server/app.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/server/app.js b/server/app.js index 4186f04d..960a8e5a 100644 --- a/server/app.js +++ b/server/app.js @@ -57,7 +57,7 @@ function startClustered(redis_enabled) { function startSingle(clustered, redis_enabled) { var client = require('./client.js'); var admin = require('./admin.js'); - var server; + var client_server; var admin_server; try { var cert_config = require(path.join(path.join(__dirname, 'config'), 'cert_config.js')); @@ -72,12 +72,12 @@ function startSingle(clustered, redis_enabled) { }; var https = require('https'); - server = https.Server(credentials, client); + client_server = https.Server(credentials, client); admin_server = https.Server(credentials, admin); } catch(err){ console.log("Starting without https (probably on localhost)"); - server = http.Server(client); + client_server = http.Server(client); admin_server = http.Server(admin); //add = ",http://localhost:80*,http://localhost:8080*,localhost:8080*, localhost:8082*,http://zoff.dev:80*,http://zoff.dev:8080*,zoff.dev:8080*, zoff.dev:8082*"; } @@ -87,10 +87,10 @@ function startSingle(clustered, redis_enabled) { if(clustered) { app .use( vhost('*', function(req, res) { - server.emit("request", req, res); + client_server.emit("request", req, res); }) ) .use( vhost('remote.*', function(req, res) { - server.emit("request", req, res); + client_server.emit("request", req, res); }) ) .use( vhost('admin.*', function(req, res) { admin_server.emit("request", req, res); @@ -100,10 +100,10 @@ function startSingle(clustered, redis_enabled) { } else { app .use( vhost('*', function(req, res) { - server.emit("request", req, res); + client_server.emit("request", req, res); }) ) .use( vhost('remote.*', function(req, res) { - server.emit("request", req, res); + client_server.emit("request", req, res); }) ) .use( vhost('admin.*', function(req, res) { admin_server.emit("request", req, res); @@ -121,16 +121,16 @@ function startSingle(clustered, redis_enabled) { } catch(e) { console.log("No redis-server to connect to.."); } - socketIO.listen(server); + socketIO.listen(client_server); } else { - socketIO.listen(server); + socketIO.listen(client_server); } process.on('message', function(message, connection) { if (message !== 'sticky-session:connection') { return; } - server.emit('connection', connection); + client_server.emit('connection', connection); connection.resume(); }); From fedaedca8cdc6ea212813da5f149fc1b742c75e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Mon, 5 Feb 2018 20:53:26 +0100 Subject: [PATCH 3/3] Working adminpanel hopefully --- server/app.js | 47 +++++++++++++++++++-------------- server/routing/client/router.js | 4 +-- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/server/app.js b/server/app.js index 960a8e5a..a94779b8 100644 --- a/server/app.js +++ b/server/app.js @@ -45,7 +45,7 @@ function startClustered(redis_enabled) { return Number(s) % len; }; - var server = net.createServer({ pauseOnConnect: true }, function(connection) { + var server = net.createServer({ pauseOnConnect: true }, function(connection, a) { var worker = workers[worker_index(connection.remoteAddress, num_processes)]; worker.send('sticky-session:connection', connection); }).listen(port); @@ -55,10 +55,8 @@ function startClustered(redis_enabled) { } function startSingle(clustered, redis_enabled) { + var server; var client = require('./client.js'); - var admin = require('./admin.js'); - var client_server; - var admin_server; try { var cert_config = require(path.join(path.join(__dirname, 'config'), 'cert_config.js')); var fs = require('fs'); @@ -72,41 +70,36 @@ function startSingle(clustered, redis_enabled) { }; var https = require('https'); - client_server = https.Server(credentials, client); - admin_server = https.Server(credentials, admin); - + server = https.Server(credentials, routingFunction); } catch(err){ console.log("Starting without https (probably on localhost)"); - client_server = http.Server(client); - admin_server = http.Server(admin); + server = http.createServer(routingFunction); //add = ",http://localhost:80*,http://localhost:8080*,localhost:8080*, localhost:8082*,http://zoff.dev:80*,http://zoff.dev:8080*,zoff.dev:8080*, zoff.dev:8082*"; } - - if(clustered) { app .use( vhost('*', function(req, res) { - client_server.emit("request", req, res); + server.emit("request", req, res); }) ) .use( vhost('remote.*', function(req, res) { - client_server.emit("request", req, res); + server.emit("request", req, res); }) ) .use( vhost('admin.*', function(req, res) { - admin_server.emit("request", req, res); + server.emit("request", req, res); }) ) .listen(onListen); //server.listen(onListen); } else { app .use( vhost('*', function(req, res) { - client_server.emit("request", req, res); + server.emit("request", req, res); }) ) .use( vhost('remote.*', function(req, res) { - client_server.emit("request", req, res); + server.emit("request", req, res); }) ) .use( vhost('admin.*', function(req, res) { - admin_server.emit("request", req, res); + server.emit("request", req, res); }) ) .listen(port, onListen); //server.listen(port, onListen); @@ -121,16 +114,17 @@ function startSingle(clustered, redis_enabled) { } catch(e) { console.log("No redis-server to connect to.."); } - socketIO.listen(client_server); + socketIO.listen(server); } else { - socketIO.listen(client_server); + socketIO.listen(server); } + process.on('message', function(message, connection) { if (message !== 'sticky-session:connection') { return; } - client_server.emit('connection', connection); + server.emit('connection', connection); connection.resume(); }); @@ -139,3 +133,16 @@ function startSingle(clustered, redis_enabled) { function onListen() { console.log("Started with pid [" + process.pid + "]"); } + +function routingFunction(req, res, next) { + var client = require('./client.js'); + var admin = require('./admin.js'); + var url = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'] : req.headers.host.split(":")[0]; + var subdomain = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'].split(".") : req.headers.host.split(":")[0].split("."); + + if(subdomain.length > 1 && subdomain[0] == "admin") { + admin(req, res, next); + } else { + client(req, res, next); + } +} diff --git a/server/routing/client/router.js b/server/routing/client/router.js index 142c0ebe..b3e71fb0 100644 --- a/server/routing/client/router.js +++ b/server/routing/client/router.js @@ -46,7 +46,7 @@ function root(req, res, next) { try{ var url = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'] : req.headers.host.split(":")[0]; var subdomain = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'].split(".") : req.headers.host.split(":")[0].split("."); - if(url != "zoff.me" && url != "admin.zoff.me" && url != "remote.zoff.me" && url != "fb.zoff.me" && url != "remote.localhost" && url != "localhost") { + if(url != "zoff.me" && url != "admin.localhost" && url != "admin.zoff.me" && url != "remote.zoff.me" && url != "fb.zoff.me" && url != "remote.localhost" && url != "localhost") { res.redirect("https://zoff.me"); return; } @@ -77,7 +77,7 @@ function channel(req, res, next) { try{ var url = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'] : req.headers.host.split(":")[0]; var subdomain = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'].split(".") : req.headers.host.split(":")[0].split("."); - if(url != "zoff.me" && url != "admin.zoff.me" && url != "remote.zoff.me" && url != "fb.zoff.me" && url != "remote.localhost" && url != "localhost") { + if(url != "zoff.me" && url != "admin.localhost" && url != "admin.zoff.me" && url != "remote.zoff.me" && url != "fb.zoff.me" && url != "remote.localhost" && url != "localhost") { res.redirect("https://zoff.me"); return; }