I want to serve the swagger-ui using gorilla/mux and http.FileServer.
This is the routing that works so far:
router := mux.NewRouter() router.PathPrefix("/swagger-ui/").Handler(http.StripPrefix("/swagger-ui/", http.FileServer(http.Dir("swagger-ui/")))) http.ListenAndServe(":8080", router) The problem is: only a GET /swagger-ui/ returns the swagger page. When I do (what most users also expect) a GET /swagger-ui without trailing slash I get a 404.
How can this be solved?
/swagger-uiand redirect with 301 http code to/swagger-ui/. This is in case when gorilla can't help you in more elegant way :-)/swagger-ui/. and/swagger-uiis not equal to/swagger-ui/, so that't not being removed/stripped, resulting 404!