File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -18,14 +18,22 @@ func main() {
18
18
19
19
app .UseMiddleware (func (_ http.Handler ) http.Handler {
20
20
return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
21
- // check if the path has a file extension
22
- ok , _ := regexp .MatchString (`\.\S+$` , r .URL .Path )
21
+ filePath := filepath .Join (staticFilePath , r .URL .Path )
23
22
24
- if r .URL .Path != "/" && ! ok {
25
- r .URL .Path += ".html"
23
+ // check if the path has a file extension
24
+ ok , _ := regexp .MatchString (`\.\S+$` , filePath )
25
+
26
+ if r .URL .Path == "/" {
27
+ filePath = "/index.html"
28
+ } else if ! ok {
29
+ if stat , err := os .Stat (filePath ); err == nil && stat .IsDir () {
30
+ filePath = filepath .Join (r .URL .Path , "/index.html" )
31
+ } else {
32
+ r .URL .Path += ".html"
33
+ }
26
34
}
27
35
28
- filePath : = filepath .Join (staticFilePath , r .URL .Path )
36
+ filePath = filepath .Join (staticFilePath , r .URL .Path )
29
37
if _ , err := os .Stat (filePath ); os .IsNotExist (err ) {
30
38
r .URL .Path = "/404.html"
31
39
You can’t perform that action at this time.
0 commit comments