Skip to content

Commit 730bc8f

Browse files
committed
Add redirect for slash handling
1 parent a23174b commit 730bc8f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

api/api.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ func Listen() {
8484
// Init handlers
8585
lpp := strings.TrimRight(options.listenPathPrefix, "/")
8686
http.Handle("/", http.StripPrefix(options.listenPathPrefix, assets.PublicHandler()))
87+
if lpp != "" {
88+
http.HandleFunc(fmt.Sprintf("%s", lpp), RedirectHandler)
89+
}
8790
http.HandleFunc(fmt.Sprintf("%s/search", lpp), SearchHandler)
8891
http.HandleFunc(fmt.Sprintf("%s/providers", lpp), ProvidersHandler)
8992

@@ -131,6 +134,11 @@ func checkProvider(provider string) bool {
131134
return false
132135
}
133136

137+
// RedirectHandler
138+
func RedirectHandler(w http.ResponseWriter, req *http.Request) {
139+
http.Redirect(w, req, options.listenPathPrefix, 301)
140+
}
141+
134142
// SearchHandler is the handler for the search route
135143
func SearchHandler(w http.ResponseWriter, req *http.Request) {
136144

0 commit comments

Comments
 (0)