Skip to content

Commit

Permalink
Improve the webserver's constructor
Browse files Browse the repository at this point in the history
This makes the webserver configurable during instantiation rather than
having to set the parameters afterwards.
  • Loading branch information
timvandermeij committed Feb 17, 2024
1 parent 985ba77 commit 2e6fa79
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
3 changes: 1 addition & 2 deletions gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
)
Expand Down
11 changes: 6 additions & 5 deletions test/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
10 changes: 5 additions & 5 deletions test/webserver.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit 2e6fa79

Please sign in to comment.