intermine / bluegenes

A friendly next-generation interface for Genomic data discovery powered by InterMine
http://bluegenes.apps.intermine.org
Other
76 stars 56 forks source link

URLs with trailing slash on path are invalid routes #516

Closed heralden closed 3 years ago

heralden commented 4 years ago

If you open the URL (from a fresh window/tab) http://bluegenes.apps.intermine.org/covidmine, everything will work as it should. http://bluegenes.apps.intermine.org/covidmine/querybuilder will also work fine. But as soon as you add a trailing slash after the path (e.g. http://bluegenes.apps.intermine.org/covidmine/ or http://bluegenes.apps.intermine.org/covidmine/querybuilder/) it will only load the default mine and not the registry mine (the mine switcher also doesn't get populated).

This will probably need to be fixed in the router.

heralden commented 4 years ago

This bug basically manifests itself whenever it gets a URL path that is invalid according to the route spec.

One solution to the trailing slash issue is to redirect to the equivalent URL path without the slash, on the backend router.

M src/clj/bluegenes/handler.clj
@@ -9,12 +9,18 @@
             [ring.middleware.reload :refer [wrap-reload]]
             [ring.middleware.format :refer [wrap-restful-format]]
             [compojure.core :refer [routes]]
+            [compojure.middleware :refer [wrap-canonical-redirect]]
             [bluegenes-tool-store.core :as tool]))

 (def combined-routes
   (routes tool/routes routes/routes))

 (def handler (-> #'combined-routes
+                 ; Defaults to `remove-trailing-slash` so that we will redirect
+                 ; to the correct route when trailing slash is present in path.
+                 ; This also makes a difference for the frontend router, which
+                 ; doesn't handle trailing slashes currently.
+                 wrap-canonical-redirect
                  ; Watch changes to the .clj and hot reload them
                  wrap-reload
                  ; Add session functionality to the Ring requests

However, this doesn't fix the handling of invalid routes. I have created a separate issue (#517) for this.