Skip to content
Permalink
Browse files

Additional updates, working on getting a stable client/service release.

  • Loading branch information...
roncli committed Jan 31, 2017
1 parent b981550 commit 5b1963b6422a38a2900296198735b116149fbd0f
101 index.js
@@ -1,84 +1,25 @@
var cluster = require("cluster"),
webserver = require("./webserver"),
websocket = require("./websocket"),
webServerWorker, webSocketWorker;

// A safe regexp exec method that does not leak memory.
RegExp.prototype.safeexec = function(string) {
"use strict";

var result = this.exec(string);

if (result) {
result.forEach(function(item, index) {
if (typeof item === "string") {
result[index] = item.split("").join("");
} else {
result[index] = undefined;
}
});
var express = require("express"),
app = express(),
server;

// Only allow connections on the localhost.
app.use(function(req, res, next) {
if (req.headers.host === "localhost:20920") {
next();
} else {
res.status(404).send("Not found");
}
});

return result;
};

// Use clustering to spawn separate processes.
if (cluster.isMaster) {
webServerWorker = cluster.fork({
ddsnJob: "webserver"
});
webSocketWorker = cluster.fork({
ddsnJob: "websocket"
});
// Allow for static content in the public directory.
app.use(express.static("public", {index: "index.htm"}));

cluster.on("disconnect", function(worker) {
"use strict";
// Force quit Descent DSN entirely.
app.get("/quit", function(req, res) {
res.status(200).send("Descent DSN has been force quit. You should close all other running Descent 3 servers manually.");
server.close();
});

if (worker.suicide) {
// Worker was intentionally disconnected, end the application.
if (webServerWorker.isConnected()) {
webServerWorker.kill();
}
if (webSocketWorker.isConnected()) {
webSocketWorker.kill();
}
process.exit();
} else {
// Worker was unintentionally disconnected, restart any disconnected workers.
if (!webServerWorker.isConnected()) {
webServerWorker = cluster.fork({
ddsnJob: "webserver"
});
}
if (!webSocketWorker.isConnected()) {
webSocketWorker = cluster.fork({
ddsnJob: "websocket"
});
}
}
});

cluster.on("exit", function() {
"use strict";

if (!webServerWorker.isConnected()) {
webServerWorker = cluster.fork({
ddsnJob: "webserver"
});
}
if (!webSocketWorker.isConnected()) {
webSocketWorker = cluster.fork({
ddsnJob: "websocket"
});
}
});
} else {
switch (process.env.ddsnJob) {
case "webserver":
webserver();
break;
case "websocket":
websocket();
break;
}
}
// Create the server.
server = app.listen(20920);
console.log("Listening on port 20920.");
@@ -18,7 +18,7 @@
"url": "https://github.com/roncli/descentDSNclient.git"
},
"dependencies": {
"descent3console": "0.1.8",
"descent3console": "0.1.9",
"descent3launcher": "0.1.3",
"descent3mn3tools": "0.1.3",
"express": "4.13.4",

0 comments on commit 5b1963b

Please sign in to comment.
You can’t perform that action at this time.