fix static route ordering
authorJustin Wind <justin.wind+git@gmail.com>
Sat, 19 Apr 2025 20:05:21 +0000 (13:05 -0700)
committerJustin Wind <justin.wind+git@gmail.com>
Sat, 19 Apr 2025 20:05:21 +0000 (13:05 -0700)
lib/dingus.js

index 08ebe86ec755df13c593afba0306bce422de3929..9ee9cf8608e1796a77d026f1f479f302698d814f 100644 (file)
@@ -120,15 +120,16 @@ class Dingus {
       throw new RangeError('staticRoute parameter should not have trailing slash');
     }
 
+    // /static/ serves /static/index.html
+    // define before /static/:file else :file would match ''
+    this.on(['GET'], `${opt.staticRoute}/`, this.handlerGetStaticFile.bind(this), 'index.html');
+
     // /static/:file serves file
     this.on(['GET'], `${opt.staticRoute}/:file`, opt.staticRouteFileName, this.handlerGetStaticFile.bind(this));
 
     // /static forwards to /static/
     this.on(['GET'], opt.staticRoute, this.handlerRedirect.bind(this), `${this.proxyPrefix}${opt.staticRoute}/`);
 
-    // /static/ serves /static/index.html
-    this.on(['GET'], `${opt.staticRoute}/`, this.handlerGetStaticFile.bind(this), 'index.html');
-
     // /favicon.ico and /robots.txt serve from /static/
     this.on(['GET'], '/favicon.ico', this.handlerGetStaticFile.bind(this), 'favicon.ico');
     this.on(['GET'], '/robots.txt', this.handlerGetStaticFile.bind(this), 'robots.txt');