mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Working adminpanel hopefully
This commit is contained in:
@@ -45,7 +45,7 @@ function startClustered(redis_enabled) {
|
|||||||
return Number(s) % len;
|
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)];
|
var worker = workers[worker_index(connection.remoteAddress, num_processes)];
|
||||||
worker.send('sticky-session:connection', connection);
|
worker.send('sticky-session:connection', connection);
|
||||||
}).listen(port);
|
}).listen(port);
|
||||||
@@ -55,10 +55,8 @@ function startClustered(redis_enabled) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function startSingle(clustered, redis_enabled) {
|
function startSingle(clustered, redis_enabled) {
|
||||||
|
var server;
|
||||||
var client = require('./client.js');
|
var client = require('./client.js');
|
||||||
var admin = require('./admin.js');
|
|
||||||
var client_server;
|
|
||||||
var admin_server;
|
|
||||||
try {
|
try {
|
||||||
var cert_config = require(path.join(path.join(__dirname, 'config'), 'cert_config.js'));
|
var cert_config = require(path.join(path.join(__dirname, 'config'), 'cert_config.js'));
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
@@ -72,41 +70,36 @@ function startSingle(clustered, redis_enabled) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var https = require('https');
|
var https = require('https');
|
||||||
client_server = https.Server(credentials, client);
|
server = https.Server(credentials, routingFunction);
|
||||||
admin_server = https.Server(credentials, admin);
|
|
||||||
|
|
||||||
} catch(err){
|
} catch(err){
|
||||||
console.log("Starting without https (probably on localhost)");
|
console.log("Starting without https (probably on localhost)");
|
||||||
client_server = http.Server(client);
|
server = http.createServer(routingFunction);
|
||||||
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*";
|
//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) {
|
if(clustered) {
|
||||||
app
|
app
|
||||||
.use( vhost('*', function(req, res) {
|
.use( vhost('*', function(req, res) {
|
||||||
client_server.emit("request", req, res);
|
server.emit("request", req, res);
|
||||||
}) )
|
}) )
|
||||||
.use( vhost('remote.*', function(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) {
|
.use( vhost('admin.*', function(req, res) {
|
||||||
admin_server.emit("request", req, res);
|
server.emit("request", req, res);
|
||||||
}) )
|
}) )
|
||||||
.listen(onListen);
|
.listen(onListen);
|
||||||
//server.listen(onListen);
|
//server.listen(onListen);
|
||||||
} else {
|
} else {
|
||||||
app
|
app
|
||||||
.use( vhost('*', function(req, res) {
|
.use( vhost('*', function(req, res) {
|
||||||
client_server.emit("request", req, res);
|
server.emit("request", req, res);
|
||||||
}) )
|
}) )
|
||||||
.use( vhost('remote.*', function(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) {
|
.use( vhost('admin.*', function(req, res) {
|
||||||
admin_server.emit("request", req, res);
|
server.emit("request", req, res);
|
||||||
}) )
|
}) )
|
||||||
.listen(port, onListen);
|
.listen(port, onListen);
|
||||||
//server.listen(port, onListen);
|
//server.listen(port, onListen);
|
||||||
@@ -121,16 +114,17 @@ function startSingle(clustered, redis_enabled) {
|
|||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log("No redis-server to connect to..");
|
console.log("No redis-server to connect to..");
|
||||||
}
|
}
|
||||||
socketIO.listen(client_server);
|
socketIO.listen(server);
|
||||||
} else {
|
} else {
|
||||||
socketIO.listen(client_server);
|
socketIO.listen(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
process.on('message', function(message, connection) {
|
process.on('message', function(message, connection) {
|
||||||
if (message !== 'sticky-session:connection') {
|
if (message !== 'sticky-session:connection') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
client_server.emit('connection', connection);
|
server.emit('connection', connection);
|
||||||
|
|
||||||
connection.resume();
|
connection.resume();
|
||||||
});
|
});
|
||||||
@@ -139,3 +133,16 @@ function startSingle(clustered, redis_enabled) {
|
|||||||
function onListen() {
|
function onListen() {
|
||||||
console.log("Started with pid [" + process.pid + "]");
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ function root(req, res, next) {
|
|||||||
try{
|
try{
|
||||||
var url = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'] : req.headers.host.split(":")[0];
|
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(".");
|
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");
|
res.redirect("https://zoff.me");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ function channel(req, res, next) {
|
|||||||
try{
|
try{
|
||||||
var url = req.headers['x-forwarded-host'] ? req.headers['x-forwarded-host'] : req.headers.host.split(":")[0];
|
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(".");
|
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");
|
res.redirect("https://zoff.me");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user