mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-17 20:55:28 +00:00
fix: serve frontend assets
This commit is contained in:
parent
399364af01
commit
101aa6a10f
@ -179,6 +179,7 @@ func (s *APIV1Service) CreateShortcut(ctx context.Context, request *apiv1pb.Crea
|
|||||||
response := &apiv1pb.CreateShortcutResponse{
|
response := &apiv1pb.CreateShortcutResponse{
|
||||||
Shortcut: composedShortcut,
|
Shortcut: composedShortcut,
|
||||||
}
|
}
|
||||||
|
metric.Enqueue("Shortcut create")
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ func NewFrontendService(profile *profile.Profile, store *store.Store) *FrontendS
|
|||||||
|
|
||||||
func (s *FrontendService) Serve(ctx context.Context, e *echo.Echo) {
|
func (s *FrontendService) Serve(ctx context.Context, 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
|
// Reference: https://github.com/labstack/echo/blob/master/middleware/static.go
|
||||||
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
||||||
HTML5: true,
|
HTML5: true,
|
||||||
Filesystem: getFileSystem("dist"),
|
Filesystem: getFileSystem("dist"),
|
||||||
@ -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.registerRoutes(e)
|
||||||
s.registerFileRoutes(ctx, e)
|
s.registerFileRoutes(ctx, e)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user