fix not found when has mulit static dir
robot &robots
Showing
1 changed file
with
8 additions
and
2 deletions
| ... | @@ -31,6 +31,7 @@ func serverStaticRouter(ctx *context.Context) { | ... | @@ -31,6 +31,7 @@ func serverStaticRouter(ctx *context.Context) { |
| 31 | return | 31 | return |
| 32 | } | 32 | } |
| 33 | requestPath := path.Clean(ctx.Input.Request.URL.Path) | 33 | requestPath := path.Clean(ctx.Input.Request.URL.Path) |
| 34 | i := 0 | ||
| 34 | for prefix, staticDir := range StaticDir { | 35 | for prefix, staticDir := range StaticDir { |
| 35 | if len(prefix) == 0 { | 36 | if len(prefix) == 0 { |
| 36 | continue | 37 | continue |
| ... | @@ -41,8 +42,13 @@ func serverStaticRouter(ctx *context.Context) { | ... | @@ -41,8 +42,13 @@ func serverStaticRouter(ctx *context.Context) { |
| 41 | http.ServeFile(ctx.ResponseWriter, ctx.Request, file) | 42 | http.ServeFile(ctx.ResponseWriter, ctx.Request, file) |
| 42 | return | 43 | return |
| 43 | } else { | 44 | } else { |
| 44 | http.NotFound(ctx.ResponseWriter, ctx.Request) | 45 | i++ |
| 45 | return | 46 | if i == len(StaticDir) { |
| 47 | http.NotFound(ctx.ResponseWriter, ctx.Request) | ||
| 48 | return | ||
| 49 | } else { | ||
| 50 | continue | ||
| 51 | } | ||
| 46 | } | 52 | } |
| 47 | } | 53 | } |
| 48 | if strings.HasPrefix(requestPath, prefix) { | 54 | if strings.HasPrefix(requestPath, prefix) { | ... | ... |
-
Please register or sign in to post a comment