Skip to content

Commit

Permalink
fix: serve frontend assets
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Apr 28, 2024
1 parent 399364a commit 101aa6a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions server/route/api/v1/shortcut_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func (s *APIV1Service) CreateShortcut(ctx context.Context, request *apiv1pb.Crea
response := &apiv1pb.CreateShortcutResponse{
Shortcut: composedShortcut,
}
metric.Enqueue("Shortcut create")
return response, nil
}

Expand Down
25 changes: 24 additions & 1 deletion server/route/frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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"),
Expand All @@ -48,6 +48,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", "/slash.api.v1", "/robots.txt", "/sitemap.xml", "/s/:shortcutName", "/c/:collectionName")
},
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", "/slash.api.v1", "/robots.txt", "/sitemap.xml", "/s/:shortcutName", "/c/:collectionName")
},
}))

s.registerRoutes(e)
s.registerFileRoutes(ctx, e)
}
Expand Down

0 comments on commit 101aa6a

Please sign in to comment.