ekko: add gzip, move recover middleware to run early

This commit is contained in:
2024-09-21 00:53:10 -07:00
parent 3f3fb29bc9
commit d6a77f4003
4 changed files with 16 additions and 25 deletions

View File

@@ -89,6 +89,14 @@ func (ek *Ekko) setup(ctx context.Context) (*echo.Echo, error) {
e.Use(ek.otelmiddleware)
}
e.Use(middleware.RecoverWithConfig(middleware.RecoverConfig{
LogErrorFunc: func(c echo.Context, err error, stack []byte) error {
log.ErrorContext(c.Request().Context(), err.Error(), "stack", string(stack))
fmt.Println(string(stack))
return err
},
}))
e.Use(slogecho.NewWithConfig(log,
slogecho.Config{
WithTraceID: false, // done by logger already
@@ -102,6 +110,8 @@ func (ek *Ekko) setup(ctx context.Context) (*echo.Echo, error) {
}))
}
e.Use(middleware.Gzip())
e.Use(middleware.Secure())
e.Use(
@@ -133,14 +143,6 @@ func (ek *Ekko) setup(ctx context.Context) (*echo.Echo, error) {
}
})
// todo: do we want this?
e.Use(middleware.RecoverWithConfig(middleware.RecoverConfig{
LogErrorFunc: func(c echo.Context, err error, stack []byte) error {
log.ErrorContext(c.Request().Context(), err.Error(), "stack", string(stack))
return err
},
}))
if ek.routeFn != nil {
err := ek.routeFn(e)
if err != nil {