Commit f3580a88bea0

Vincent Demeester <vincent@sbr.pm>
2025-12-01 11:54:29
feat: Add trailing slash redirect for Syncthing routes
- Redirect s.sbr.pm/{machine} to s.sbr.pm/{machine}/ automatically - Ensure consistent URL handling for all Syncthing instances - Prevent application errors from missing trailing slashes Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent ec6672f
Changed files (1)
systems
systems/rhea/extra.nix
@@ -77,7 +77,10 @@
               rule = "Host(`syncthing.sbr.pm`) && PathPrefix(`/${name}`) || Host(`s.sbr.pm`) && PathPrefix(`/${name}`)";
               service = "syncthing-${name}";
               entryPoints = [ "websecure" ];
-              middlewares = [ "syncthing-${name}-strip" ];
+              middlewares = [
+                "syncthing-${name}-addslash"
+                "syncthing-${name}-strip"
+              ];
               tls = {
                 certResolver = "letsencrypt";
               };
@@ -105,6 +108,18 @@
               };
             }
           ) syncthingMachines;
+
+          # Generate middleware for adding trailing slash
+          syncthingAddSlashMiddlewares = lib.mapAttrs' (
+            name: _machine:
+            lib.nameValuePair "syncthing-${name}-addslash" {
+              redirectRegex = {
+                regex = "^(https?://[^/]+/${name})$";
+                replacement = "$${1}/";
+                permanent = true;
+              };
+            }
+          ) syncthingMachines;
         in
         {
           http = {
@@ -247,7 +262,7 @@
                 };
               };
             };
-            middlewares = syncthingMiddlewares;
+            middlewares = syncthingMiddlewares // syncthingAddSlashMiddlewares;
           };
           tcp = {
             routers = {