mirror of
https://github.com/nkanaev/yarr.git
synced 2025-09-15 19:00:15 +00:00
router: handle urls without base properly
This commit is contained in:
@@ -50,9 +50,15 @@ func (r *Router) resolve(path string) *Route {
|
||||
|
||||
func (r *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
// autoclose open base url
|
||||
if r.base != "" && r.base == req.URL.Path {
|
||||
http.Redirect(rw, req, r.base+"/", http.StatusFound)
|
||||
return
|
||||
if r.base != "" {
|
||||
if r.base == req.URL.Path {
|
||||
http.Redirect(rw, req, r.base+"/", http.StatusFound)
|
||||
return
|
||||
}
|
||||
if !strings.HasPrefix(req.URL.Path, r.base) {
|
||||
rw.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
path := strings.TrimPrefix(req.URL.Path, r.base)
|
||||
|
Reference in New Issue
Block a user