@@ -55,7 +55,7 @@ var WrapHandler = EchoWrapHandler()
55
55
func EchoWrapHandler (configFns ... func (c * Config )) echo.HandlerFunc {
56
56
var once sync.Once
57
57
58
- handler := swaggerFiles .Handler
58
+ h := swaggerFiles .Handler
59
59
60
60
config := & Config {
61
61
URL : "doc.json" ,
@@ -72,21 +72,20 @@ func EchoWrapHandler(configFns ...func(c *Config)) echo.HandlerFunc {
72
72
t := template .New ("swagger_index.html" )
73
73
index , _ := t .Parse (indexTemplate )
74
74
75
- var re = regexp .MustCompile (`(.*)(index\.html|doc\.json|favicon-16x16\.png|favicon-32x32\.png|/oauth2-redirect\.html|swagger-ui\.css|swagger-ui\.css\.map|swagger-ui\.js|swagger-ui\.js\.map|swagger-ui-bundle\.js|swagger-ui-bundle\.js\.map|swagger-ui-standalone-preset\.js|swagger-ui-standalone-preset\.js\.map) [?|.]*` )
75
+ var re = regexp .MustCompile (`^ (.*/)([^?].*)? [?|.]*$ ` )
76
76
77
77
return func (c echo.Context ) error {
78
- var matches []string
79
- if matches = re .FindStringSubmatch (c .Request ().RequestURI ); len (matches ) != 3 {
80
- return c .String (http .StatusNotFound , "404 page not found" )
81
- }
78
+ matches := re .FindStringSubmatch (c .Request ().RequestURI )
82
79
path := matches [2 ]
80
+
83
81
once .Do (func () {
84
- handler .Prefix = matches [1 ]
82
+ h .Prefix = matches [1 ]
85
83
})
86
84
87
85
defer c .Response ().Flush ()
88
-
89
86
switch path {
87
+ case "" :
88
+ c .Redirect (301 , h .Prefix + "index.html" )
90
89
case "index.html" :
91
90
_ = index .Execute (c .Response ().Writer , config )
92
91
case "doc.json" :
@@ -100,7 +99,7 @@ func EchoWrapHandler(configFns ...func(c *Config)) echo.HandlerFunc {
100
99
c .Response ().Writer .Header ().Set ("Content-Type" , "application/json; charset=utf-8" )
101
100
_ , _ = c .Response ().Writer .Write ([]byte (doc ))
102
101
default :
103
- handler .ServeHTTP (c .Response ().Writer , c .Request ())
102
+ h .ServeHTTP (c .Response ().Writer , c .Request ())
104
103
}
105
104
106
105
return nil
0 commit comments