Improve the webserver's constructor
This makes the webserver configurable during instantiation rather than having to set the parameters afterwards.
This commit is contained in:
parent
985ba77579
commit
2e6fa797d9
@ -2068,8 +2068,7 @@ gulp.task(
|
|||||||
console.log("### Starting local server");
|
console.log("### Starting local server");
|
||||||
|
|
||||||
const { WebServer } = await import("./test/webserver.mjs");
|
const { WebServer } = await import("./test/webserver.mjs");
|
||||||
const server = new WebServer();
|
const server = new WebServer({ port: 8888 });
|
||||||
server.port = 8888;
|
|
||||||
server.start();
|
server.start();
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -1015,11 +1015,12 @@ async function startBrowsers({ baseUrl, initializeSession }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function startServer() {
|
function startServer() {
|
||||||
server = new WebServer();
|
server = new WebServer({
|
||||||
server.host = host;
|
root: "..",
|
||||||
server.port = options.port;
|
host,
|
||||||
server.root = "..";
|
port: options.port,
|
||||||
server.cacheExpirationTime = 3600;
|
cacheExpirationTime: 3600,
|
||||||
|
});
|
||||||
server.start();
|
server.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,13 +38,13 @@ const MIME_TYPES = {
|
|||||||
const DEFAULT_MIME_TYPE = "application/octet-stream";
|
const DEFAULT_MIME_TYPE = "application/octet-stream";
|
||||||
|
|
||||||
class WebServer {
|
class WebServer {
|
||||||
constructor() {
|
constructor({ root, host, port, cacheExpirationTime }) {
|
||||||
this.root = ".";
|
this.root = root || ".";
|
||||||
this.host = "localhost";
|
this.host = host || "localhost";
|
||||||
this.port = 0;
|
this.port = port || 0;
|
||||||
this.server = null;
|
this.server = null;
|
||||||
this.verbose = false;
|
this.verbose = false;
|
||||||
this.cacheExpirationTime = 0;
|
this.cacheExpirationTime = cacheExpirationTime || 0;
|
||||||
this.disableRangeRequests = false;
|
this.disableRangeRequests = false;
|
||||||
this.hooks = {
|
this.hooks = {
|
||||||
GET: [crossOriginHandler],
|
GET: [crossOriginHandler],
|
||||||
|
Loading…
Reference in New Issue
Block a user