mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: update assets routes
This commit is contained in:
@@ -30,26 +30,28 @@ func NewFrontendService(profile *profile.Profile, store *store.Store) *FrontendS
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (*FrontendService) Serve(_ context.Context, e *echo.Echo) {
|
func (*FrontendService) Serve(_ context.Context, e *echo.Echo) {
|
||||||
skipper := func(c echo.Context) bool {
|
apiSkipper := func(c echo.Context) bool {
|
||||||
return util.HasPrefixes(c.Path(), "/api", "/memos.api.v1")
|
return util.HasPrefixes(c.Path(), "/api", "/memos.api.v1")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Route to serve the assets folder without HTML5 fallback.
|
// Route to serve the main app with HTML5 fallback for SPA behavior.
|
||||||
e.Group("/assets").Use(func(next echo.HandlerFunc) echo.HandlerFunc {
|
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
return func(c echo.Context) error {
|
return func(c echo.Context) error {
|
||||||
|
// Skip API routes.
|
||||||
|
if apiSkipper(c) {
|
||||||
|
return next(c)
|
||||||
|
}
|
||||||
|
// Skip `/index.html`.
|
||||||
|
if c.Path() == "/index.html" {
|
||||||
|
return next(c)
|
||||||
|
}
|
||||||
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)
|
||||||
}
|
}
|
||||||
}, middleware.StaticWithConfig(middleware.StaticConfig{
|
}, middleware.StaticWithConfig(middleware.StaticConfig{
|
||||||
Filesystem: getFileSystem("dist/assets"),
|
|
||||||
HTML5: false, // Disable fallback to index.html
|
|
||||||
}))
|
|
||||||
|
|
||||||
// Route to serve the main app with HTML5 fallback for SPA behavior.
|
|
||||||
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
|
||||||
Filesystem: getFileSystem("dist"),
|
Filesystem: getFileSystem("dist"),
|
||||||
HTML5: true, // Enable fallback to index.html
|
HTML5: true, // Enable fallback to index.html
|
||||||
Skipper: skipper,
|
Skipper: apiSkipper,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user