Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

fix: serve frontend assets

Stevenf25c7d9b2492
diff --git a/server/route/frontend/frontend.go b/server/route/frontend/frontend.go
index 5a193536f..c8db8a6dd 100644
--- a/server/route/frontend/frontend.go
+++ b/server/route/frontend/frontend.go
@@ -41,7 +41,7 @@ func NewFrontendService(profile *profile.Profile, store *store.Store) *FrontendS
func (s *FrontendService) Serve(ctx context.Context, e *echo.Echo) {
// Use echo static middleware to serve the built dist folder.
- // refer: https://github.com/labstack/echo/blob/master/middleware/static.go
+ // Reference: https://github.com/labstack/echo/blob/master/middleware/static.go
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
HTML5: true,
Filesystem: getFileSystem("dist"),
@@ -50,6 +50,29 @@ func (s *FrontendService) Serve(ctx context.Context, e *echo.Echo) {
},
}))
+ g := e.Group("assets")
+ // Use echo gzip middleware to compress the response.
+ // Reference: https://echo.labstack.com/docs/middleware/gzip
+ g.Use(middleware.GzipWithConfig(middleware.GzipConfig{
+ Skipper: func(c echo.Context) bool {
+ return util.HasPrefixes(c.Path(), "/api", "/memos.api.v1", "/robots.txt", "/sitemap.xml", "/m/:name")
+ },
+ Level: 5,
+ }))
+ g.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
+ return func(c echo.Context) error {
+ c.Response().Header().Set(echo.HeaderCacheControl, "max-age=31536000, immutable")
+ return next(c)
+ }
+ })
+ g.Use(middleware.StaticWithConfig(middleware.StaticConfig{
+ HTML5: true,
+ Filesystem: getFileSystem("dist/assets"),
+ Skipper: func(c echo.Context) bool {
+ return util.HasPrefixes(c.Path(), "/api", "/memos.api.v1", "/robots.txt", "/sitemap.xml", "/m/:name")
+ },
+ }))
+
s.registerRoutes(e)
s.registerFileRoutes(ctx, e)
}