769f7c75 by asta.xie

fix static file route

1 parent a8c2deb0
...@@ -546,6 +546,9 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -546,6 +546,9 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
546 546
547 //static file server 547 //static file server
548 for prefix, staticDir := range StaticDir { 548 for prefix, staticDir := range StaticDir {
549 if len(prefix) == 0 {
550 continue
551 }
549 if r.URL.Path == "/favicon.ico" { 552 if r.URL.Path == "/favicon.ico" {
550 file := path.Join(staticDir, r.URL.Path) 553 file := path.Join(staticDir, r.URL.Path)
551 if utils.FileExists(file) { 554 if utils.FileExists(file) {
...@@ -558,6 +561,10 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -558,6 +561,10 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
558 if len(r.URL.Path) > len(prefix) && r.URL.Path[len(prefix)] != '/' { 561 if len(r.URL.Path) > len(prefix) && r.URL.Path[len(prefix)] != '/' {
559 continue 562 continue
560 } 563 }
564 if r.URL.Path == prefix && prefix[len(prefix)-1] != '/' {
565 http.Redirect(rw, r, r.URL.Path+"/", 302)
566 goto Admin
567 }
561 file := path.Join(staticDir, r.URL.Path[len(prefix):]) 568 file := path.Join(staticDir, r.URL.Path[len(prefix):])
562 finfo, err := os.Stat(file) 569 finfo, err := os.Stat(file)
563 if err != nil { 570 if err != nil {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!