Skip to content

Commit e4f0798

Browse files
committed
Tidy up redirection to /app/
1 parent 68c5917 commit e4f0798

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

service/cmd/webapp/main.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,19 @@ func main() {
5858

5959
// Application (SPA - Reactjs)
6060
{
61-
// We can use a prefix for the SPA app, as long as we specify the same prefix in the "homepage" field
62-
// in the package.json file...
63-
// ```
64-
// {
65-
// "homepage": "/app"
66-
// }
67-
//
68-
// $ npm run build
69-
// ```
7061
prefix := "/app"
71-
// Create a subrouter at the prefix path
72-
appSubRouter := router.PathPrefix(prefix).Subrouter()
73-
// Create the app route handler with the subrouter and the prefix.
74-
newAppRouter(prefix, appSubRouter)
62+
63+
// The Single-Page-Application should be delivered from the prefix path with a trailing '/'.
64+
// This is important to ensure that relative paths used within the SPA inherit the full path,
65+
// including the prefix.
66+
spaPrefix := prefix + "/"
67+
appSubRouter := router.PathPrefix(spaPrefix).Subrouter() // Subrouter for SPA
68+
newAppRouter(prefix, appSubRouter) // Handler for SPA
69+
70+
// For the 'bare' prefix path (with no trailing '/') we redirect to add the trailing '/',
71+
// being careful to use a relative path here.
72+
redirectionPrefix := "." + spaPrefix
73+
router.PathPrefix(prefix).Handler(http.RedirectHandler(redirectionPrefix, http.StatusTemporaryRedirect))
7574
}
7675

7776
// static assets

0 commit comments

Comments
 (0)