move control handler to own function

This commit is contained in:
AJ ONeal 2018-10-15 21:02:57 -06:00
parent e0ea17a377
commit a6e4bda317
1 changed files with 347 additions and 338 deletions

View File

@ -326,8 +326,15 @@ controllers.ssh = function (req, res, opts) {
state.config.sshAuto = sshAuto; state.config.sshAuto = sshAuto;
sshSuccess(); sshSuccess();
}; };
function serveControlsHelper() {
controlServer = http.createServer(function (req, res) { var serveStatic = require('serve-static')(path.join(__dirname, '../lib/admin/'));
function handleRemoteClient(req, res) {
if (/^\/(rpc|api)\//.test(req.url)) {
return handleApi(req, res);
}
serveStatic(req, res, require('finalhandler')(req, res));
}
function handleApi(req, res) {
var opts = url.parse(req.url, true); var opts = url.parse(req.url, true);
if (false && opts.query._body) { if (false && opts.query._body) {
try { try {
@ -675,7 +682,9 @@ function serveControlsHelper() {
} }
route(); route();
}); });
}); }
function serveControlsHelper() {
controlServer = http.createServer(handleRemoteClient);
if (fs.existsSync(state._ipc.path)) { if (fs.existsSync(state._ipc.path)) {
fs.unlinkSync(state._ipc.path); fs.unlinkSync(state._ipc.path);