mirror of
https://github.com/usememos/memos.git
synced 2025-02-12 01:10:38 +01:00
fix: skip api error for static middleware (#941)
This commit is contained in:
parent
1441a1df1f
commit
40d25f7dca
@ -22,6 +22,11 @@ func DefaultGetRequestSkipper(c echo.Context) bool {
|
|||||||
return c.Request().Method == http.MethodGet
|
return c.Request().Method == http.MethodGet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DefaultAPIRequestSkipper(c echo.Context) bool {
|
||||||
|
path := c.Path()
|
||||||
|
return common.HasPrefixes(path, "/api")
|
||||||
|
}
|
||||||
|
|
||||||
func (server *Server) DefaultAuthSkipper(c echo.Context) bool {
|
func (server *Server) DefaultAuthSkipper(c echo.Context) bool {
|
||||||
ctx := c.Request().Context()
|
ctx := c.Request().Context()
|
||||||
path := c.Path()
|
path := c.Path()
|
||||||
|
@ -25,18 +25,19 @@ func embedFrontend(e *echo.Echo) {
|
|||||||
// Use echo static middleware to serve the built dist folder
|
// Use echo static middleware to serve the built dist folder
|
||||||
// refer: https://github.com/labstack/echo/blob/master/middleware/static.go
|
// refer: https://github.com/labstack/echo/blob/master/middleware/static.go
|
||||||
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
||||||
|
Skipper: DefaultAPIRequestSkipper,
|
||||||
HTML5: true,
|
HTML5: true,
|
||||||
Filesystem: getFileSystem("dist"),
|
Filesystem: getFileSystem("dist"),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
g := e.Group("assets")
|
assetsGroup := e.Group("assets")
|
||||||
g.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
|
assetsGroup.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
return func(c echo.Context) error {
|
return func(c echo.Context) error {
|
||||||
c.Response().Header().Set(echo.HeaderCacheControl, "max-age=31536000, immutable")
|
c.Response().Header().Set(echo.HeaderCacheControl, "max-age=31536000, immutable")
|
||||||
return next(c)
|
return next(c)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
g.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
assetsGroup.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
||||||
HTML5: true,
|
HTML5: true,
|
||||||
Filesystem: getFileSystem("dist/assets"),
|
Filesystem: getFileSystem("dist/assets"),
|
||||||
}))
|
}))
|
||||||
|
@ -56,9 +56,7 @@ func NewServer(ctx context.Context, profile *profile.Profile) (*Server, error) {
|
|||||||
e.Use(middleware.Gzip())
|
e.Use(middleware.Gzip())
|
||||||
|
|
||||||
e.Use(middleware.CSRFWithConfig(middleware.CSRFConfig{
|
e.Use(middleware.CSRFWithConfig(middleware.CSRFConfig{
|
||||||
Skipper: func(c echo.Context) bool {
|
Skipper: s.DefaultAuthSkipper,
|
||||||
return s.DefaultAuthSkipper(c)
|
|
||||||
},
|
|
||||||
TokenLookup: "cookie:_csrf",
|
TokenLookup: "cookie:_csrf",
|
||||||
}))
|
}))
|
||||||
|
|
||||||
@ -73,7 +71,6 @@ func NewServer(ctx context.Context, profile *profile.Profile) (*Server, error) {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
e.Use(middleware.TimeoutWithConfig(middleware.TimeoutConfig{
|
e.Use(middleware.TimeoutWithConfig(middleware.TimeoutConfig{
|
||||||
Skipper: middleware.DefaultSkipper,
|
|
||||||
ErrorMessage: "Request timeout",
|
ErrorMessage: "Request timeout",
|
||||||
Timeout: 30 * time.Second,
|
Timeout: 30 * time.Second,
|
||||||
}))
|
}))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user