From 7b4612e8b011b75b5749acade71e9900c2b334b2 Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Sun, 25 Aug 2024 16:51:25 +0200 Subject: [PATCH] Move commands in index.js --- src/index.js | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/index.js b/src/index.js index b1c3f6a..0682033 100644 --- a/src/index.js +++ b/src/index.js @@ -482,6 +482,27 @@ let middleware = [ require("./middleware/staticFileServingAndDirectoryListings.js"), ]; +// HTTP server handlers +const requestHandler = require("./handlers/requestHandler.js")( + serverconsole, + middleware, +); + +const proxyHandler = require("./handlers/proxyHandler.js")( + serverconsole, + middleware, +); + +const clientErrorHandler = require("./handlers/clientErrorHandler.js")( + serverconsole, +); + +// Create HTTP server +const server = http + .createServer(requestHandler) + .on("connect", proxyHandler) + .on("clientError", clientErrorHandler); + // TODO: close, open, stop, restart commands // Base commands let commands = { @@ -525,27 +546,9 @@ middleware.forEach((middlewareO) => { } }); -// HTTP server handlers -const requestHandler = require("./handlers/requestHandler.js")( - serverconsole, - middleware, -); - -const proxyHandler = require("./handlers/proxyHandler.js")( - serverconsole, - middleware, -); - -const clientErrorHandler = require("./handlers/clientErrorHandler.js")( - serverconsole, -); - -// Create HTTP server -http - .createServer(requestHandler) - .on("connect", proxyHandler) - .on("clientError", clientErrorHandler) - .listen(3000); +// TODO: HTTP ports +// Listen HTTP server to port 3000 +server.listen(3000); // TODO: error logging if (wwwrootError) throw wwwrootError;