From 1d3ae7c822e76842af4a9feb78707c6a61949982 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Wed, 14 Dec 2022 20:32:26 +0100 Subject: [PATCH] Check auth before serving static files --- server/http_server.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/server/http_server.ts b/server/http_server.ts index cb25d422..3c268531 100644 --- a/server/http_server.ts +++ b/server/http_server.ts @@ -68,6 +68,8 @@ export class HttpServer { await this.systemBoot.ensureSpaceIndex(); await this.ensureAndLoadSettings(); + this.addPasswordAuth(this.app); + // Serve static files (javascript, css, html) this.app.use(async ({ request, response }, next) => { if (request.url.pathname === "/") { @@ -111,8 +113,6 @@ export class HttpServer { } }); - this.addPasswordAuth(this.app); - // Pages API const fsRouter = this.buildFsRouter(this.systemBoot.spacePrimitives); this.app.use(fsRouter.routes()); @@ -132,12 +132,18 @@ export class HttpServer { }); this.abortController = new AbortController(); - this.app.listen({ hostname: this.hostname, port: this.port, signal: this.abortController.signal }) + this.app.listen({ + hostname: this.hostname, + port: this.port, + signal: this.abortController.signal, + }) .catch((e: any) => { console.log("Server listen error:", e.message); Deno.exit(1); }); - const visibleHostname = this.hostname === "0.0.0.0" ? "localhost" : this.hostname; + const visibleHostname = this.hostname === "0.0.0.0" + ? "localhost" + : this.hostname; console.log( `Silver Bullet is now running: http://${visibleHostname}:${this.port}`, );