enhance the static file path. If user foget / path.Join will auto fix it.
Showing
1 changed file
with
3 additions
and
2 deletions
| ... | @@ -8,6 +8,7 @@ import ( | ... | @@ -8,6 +8,7 @@ import ( |
| 8 | "net/http" | 8 | "net/http" |
| 9 | "net/url" | 9 | "net/url" |
| 10 | "os" | 10 | "os" |
| 11 | "path" | ||
| 11 | "reflect" | 12 | "reflect" |
| 12 | "regexp" | 13 | "regexp" |
| 13 | "runtime" | 14 | "runtime" |
| ... | @@ -546,13 +547,13 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) | ... | @@ -546,13 +547,13 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) |
| 546 | //static file server | 547 | //static file server |
| 547 | for prefix, staticDir := range StaticDir { | 548 | for prefix, staticDir := range StaticDir { |
| 548 | if r.URL.Path == "/favicon.ico" { | 549 | if r.URL.Path == "/favicon.ico" { |
| 549 | file := staticDir + r.URL.Path | 550 | file := path.Join(staticDir, r.URL.Path) |
| 550 | http.ServeFile(w, r, file) | 551 | http.ServeFile(w, r, file) |
| 551 | w.started = true | 552 | w.started = true |
| 552 | goto Admin | 553 | goto Admin |
| 553 | } | 554 | } |
| 554 | if strings.HasPrefix(r.URL.Path, prefix) { | 555 | if strings.HasPrefix(r.URL.Path, prefix) { |
| 555 | file := staticDir + r.URL.Path[len(prefix):] | 556 | file := path.Join(staticDir, r.URL.Path[len(prefix):]) |
| 556 | finfo, err := os.Stat(file) | 557 | finfo, err := os.Stat(file) |
| 557 | if err != nil { | 558 | if err != nil { |
| 558 | if RunMode == "dev" { | 559 | if RunMode == "dev" { | ... | ... |
-
Please register or sign in to post a comment