04a19685 by asta.xie

enhance the static file path. If user foget / path.Join will auto fix it.

1 parent 62555771
...@@ -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" {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!