From 2e6fa797d94f08eb8438a375ae3b747c2294e598 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sat, 17 Feb 2024 16:12:26 +0100 Subject: [PATCH] Improve the webserver's constructor This makes the webserver configurable during instantiation rather than having to set the parameters afterwards. --- gulpfile.mjs | 3 +-- test/test.mjs | 11 ++++++----- test/webserver.mjs | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gulpfile.mjs b/gulpfile.mjs index 484988e8e..34aba3e12 100644 --- a/gulpfile.mjs +++ b/gulpfile.mjs @@ -2068,8 +2068,7 @@ gulp.task( console.log("### Starting local server"); const { WebServer } = await import("./test/webserver.mjs"); - const server = new WebServer(); - server.port = 8888; + const server = new WebServer({ port: 8888 }); server.start(); } ) diff --git a/test/test.mjs b/test/test.mjs index 8928546d4..91c0b8262 100644 --- a/test/test.mjs +++ b/test/test.mjs @@ -1015,11 +1015,12 @@ async function startBrowsers({ baseUrl, initializeSession }) { } function startServer() { - server = new WebServer(); - server.host = host; - server.port = options.port; - server.root = ".."; - server.cacheExpirationTime = 3600; + server = new WebServer({ + root: "..", + host, + port: options.port, + cacheExpirationTime: 3600, + }); server.start(); } diff --git a/test/webserver.mjs b/test/webserver.mjs index a8265ace5..7df0ca4dc 100644 --- a/test/webserver.mjs +++ b/test/webserver.mjs @@ -38,13 +38,13 @@ const MIME_TYPES = { const DEFAULT_MIME_TYPE = "application/octet-stream"; class WebServer { - constructor() { - this.root = "."; - this.host = "localhost"; - this.port = 0; + constructor({ root, host, port, cacheExpirationTime }) { + this.root = root || "."; + this.host = host || "localhost"; + this.port = port || 0; this.server = null; this.verbose = false; - this.cacheExpirationTime = 0; + this.cacheExpirationTime = cacheExpirationTime || 0; this.disableRangeRequests = false; this.hooks = { GET: [crossOriginHandler],