2023-03-22 22:13:23 +01:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
2023-04-13 00:07:08 +02:00
|
|
|
"net/http"
|
|
|
|
|
2023-05-01 22:48:11 +02:00
|
|
|
"github.com/gorilla/sessions"
|
|
|
|
"github.com/labstack/echo-contrib/session"
|
2023-03-22 22:13:23 +01:00
|
|
|
"github.com/labstack/echo/v4/middleware"
|
|
|
|
)
|
|
|
|
|
2023-04-13 00:07:08 +02:00
|
|
|
func (a *App) SetEchoSettings() {
|
2023-03-22 23:04:57 +01:00
|
|
|
e := a.E()
|
|
|
|
|
2023-03-22 22:13:23 +01:00
|
|
|
e.HideBanner = true
|
|
|
|
|
|
|
|
e.Use(middleware.Logger())
|
2023-04-13 00:07:08 +02:00
|
|
|
// e.Use(middleware.LoggerWithConfig(
|
|
|
|
// middleware.LoggerConfig{
|
|
|
|
// Format: `{"time":"${time_rfc3339_nano}","id":"${id}","remote_ip":"${remote_ip}",` +
|
|
|
|
// `"host":"${host}","method":"${method}","uri":"${uri}","user_agent":"${user_agent}",` +
|
|
|
|
// `"status":${status},"error":"${error}","latency":${latency},"latency_human":"${latency_human}"` +
|
|
|
|
// `,"bytes_in":${bytes_in},"bytes_out":${bytes_out}}` + "\n",
|
|
|
|
// CustomTimeFormat: "2006-01-02 15:04:05.00000",
|
|
|
|
// },
|
|
|
|
// ))
|
|
|
|
// logger := zerolog.New(os.Stdout)
|
|
|
|
// e.Use(middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{
|
|
|
|
// LogURI: true,
|
|
|
|
// LogStatus: true,
|
|
|
|
// LogValuesFunc: func(c echo.Context, v middleware.RequestLoggerValues) error {
|
|
|
|
// logger.Info().
|
|
|
|
// Str("URI", v.URI).
|
|
|
|
// Int("status", v.Status).
|
|
|
|
// Msg("request")
|
|
|
|
//
|
|
|
|
// return nil
|
|
|
|
// },
|
|
|
|
// }))
|
|
|
|
|
2023-03-22 22:13:23 +01:00
|
|
|
e.Use(middleware.Recover())
|
2023-04-13 00:07:08 +02:00
|
|
|
|
2023-05-01 22:48:11 +02:00
|
|
|
e.Use(session.Middleware(sessions.NewCookieStore([]byte(a.config.SessionCookieSecret))))
|
|
|
|
|
2023-04-13 00:07:08 +02:00
|
|
|
// e.Use(middleware.CSRF())
|
|
|
|
e.Use(middleware.CSRFWithConfig(middleware.CSRFConfig{
|
|
|
|
TokenLookup: "cookie:_csrf",
|
|
|
|
CookiePath: "/",
|
|
|
|
// CookieDomain: "example.com",
|
|
|
|
// CookieSecure: true,
|
|
|
|
CookieHTTPOnly: true,
|
|
|
|
CookieSameSite: http.SameSiteStrictMode,
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
|
2023-03-22 23:15:04 +01:00
|
|
|
e.Use(middleware.Secure())
|
2023-03-22 22:13:23 +01:00
|
|
|
}
|