diff --git a/docker/devenv/files/nginx.conf b/docker/devenv/files/nginx.conf index 169706e23..d76176d45 100644 --- a/docker/devenv/files/nginx.conf +++ b/docker/devenv/files/nginx.conf @@ -192,10 +192,18 @@ http { } location / { + location ~ ^/(/|css|fonts|images|js|wasm) { + } + + location ~ ^/[^/]+/(.*)$ { + return 301 /404.html; + } + add_header Last-Modified $date_gmt; add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0'; if_modified_since off; expires off; + try_files $uri /index.html$is_args$args =404; } } } diff --git a/docker/gitpod/files/nginx.conf b/docker/gitpod/files/nginx.conf index 319b4bcbb..bff502389 100644 --- a/docker/gitpod/files/nginx.conf +++ b/docker/gitpod/files/nginx.conf @@ -131,6 +131,15 @@ http { location / { add_header Cache-Control "no-cache, max-age=0"; + + location ~ ^/(/|css|fonts|images|js|wasm) { + } + + location ~ ^/[^/]+/(.*)$ { + return 301 /404.html; + } + + try_files $uri /index.html$is_args$args =404; } } } diff --git a/docker/images/files/nginx.conf b/docker/images/files/nginx.conf index b79a07022..5ccd0d43d 100644 --- a/docker/images/files/nginx.conf +++ b/docker/images/files/nginx.conf @@ -168,7 +168,16 @@ http { location ~* \.(html).*$ { add_header Cache-Control "no-cache, max-age=0" always; } + + location ~ ^/(/|css|fonts|images|js|wasm) { + } + + location ~ ^/[^/]+/(.*)$ { + return 301 /404.html; + } + root /var/www/app/; + try_files $uri /index.html$is_args$args =404; } } } diff --git a/frontend/src/app/main/ui/routes.cljs b/frontend/src/app/main/ui/routes.cljs index 864e6b2d4..4944fcc85 100644 --- a/frontend/src/app/main/ui/routes.cljs +++ b/frontend/src/app/main/ui/routes.cljs @@ -6,8 +6,10 @@ (ns app.main.ui.routes (:require + [app.common.data.macros :as dm] [app.common.spec :as us] [app.common.uuid :as uuid] + [app.config :as cf] [app.main.data.users :as du] [app.main.repo :as rp] [app.main.store :as st] @@ -92,17 +94,33 @@ (defn on-navigate [router path] - (if-let [match (match-path router path)] - (st/emit! (rt/navigated match)) + (let [location (.-location js/document) + location-path (dm/str (.-origin location) (.-pathname location)) + valid-location? (= location-path (dm/str cf/public-uri)) + match (match-path router path) + empty-path? (or (= path "") (= path "/"))] + (cond + (not valid-location?) + (st/emit! (rt/assign-exception {:type :not-found})) - ;; We just recheck with an additional profile request; this avoids - ;; some race conditions that causes unexpected redirects on - ;; invitations workflows (and probably other cases). - (->> (rp/cmd! :get-profile) - (rx/subs (fn [{:keys [id] :as profile}] - (if (= id uuid/zero) - (st/emit! (rt/nav :auth-login)) - (st/emit! (rt/nav :dashboard-projects {:team-id (du/get-current-team-id profile)})))))))) + (some? match) + (st/emit! (rt/navigated match)) + + :else + ;; We just recheck with an additional profile request; this avoids + ;; some race conditions that causes unexpected redirects on + ;; invitations workflows (and probably other cases). + (->> (rp/cmd! :get-profile) + (rx/subs (fn [{:keys [id] :as profile}] + (cond + (= id uuid/zero) + (st/emit! (rt/nav :auth-login)) + + empty-path? + (st/emit! (rt/nav :dashboard-projects {:team-id (du/get-current-team-id profile)})) + + :else + (st/emit! (rt/assign-exception {:type :not-found}))))))))) (defn init-routes [] diff --git a/frontend/src/app/main/ui/static.cljs b/frontend/src/app/main/ui/static.cljs index 463a4e307..9164f1041 100644 --- a/frontend/src/app/main/ui/static.cljs +++ b/frontend/src/app/main/ui/static.cljs @@ -18,7 +18,7 @@ {::mf/wrap-props false} [props] (let [children (obj/get props "children") - on-click (mf/use-callback #(set! (.-href globals/location) ""))] + on-click (mf/use-callback #(set! (.-href globals/location) "/"))] [:section.exception-layout [:div.exception-header {:on-click on-click}