Enable ColorSchemeDetection middleware
- commit
- 5712188e50a164b93a2f7a812f9e2ea54af281de
- author
- bnema · · 2023-09-05 04:55 UTC
- parent
- dce1fef
- signature
- unsigned
6 files · +10 -10
M internal/http/middlewares/detect-color-scheme.go +2 -2
| @@ -10,8 +10,8 @@ import ( | |||
| 10 | 10 | // ColorSchemeKey is a key for setting and getting the color scheme from the context | |
| 11 | 11 | const ColorSchemeKey = "CurrentColorScheme" | |
| 12 | 12 | ||
| 13 | - | // ColorSchemeDetectionMiddleware detects the current color scheme and sets it in the context | |
| 14 | - | func ColorSchemeDetectionMiddleware(next echo.HandlerFunc) echo.HandlerFunc { | |
| 13 | + | // ColorSchemeDetection detects the current color scheme and sets it in the context | |
| 14 | + | func ColorSchemeDetection(next echo.HandlerFunc) echo.HandlerFunc { | |
| 15 | 15 | return func(c echo.Context) error { | |
| 16 | 16 | colorScheme := detectCurrentColorScheme(c) | |
| 17 | 17 | fmt.Println("Color scheme detected:", colorScheme) | |
| @@ -10,8 +10,8 @@ import ( | |||||
| 10 | // ColorSchemeKey is a key for setting and getting the color scheme from the context | 10 | // ColorSchemeKey is a key for setting and getting the color scheme from the context | ||
| 11 | const ColorSchemeKey = "CurrentColorScheme" | 11 | const ColorSchemeKey = "CurrentColorScheme" | ||
| 12 | 12 | ||||
| 13 | - | // ColorSchemeDetectionMiddleware detects the current color scheme and sets it in the context | 13 | + | // ColorSchemeDetection detects the current color scheme and sets it in the context |
| 14 | - | func ColorSchemeDetectionMiddleware(next echo.HandlerFunc) echo.HandlerFunc { | 14 | + | func ColorSchemeDetection(next echo.HandlerFunc) echo.HandlerFunc { |
| 15 | return func(c echo.Context) error { | 15 | return func(c echo.Context) error { | ||
| 16 | colorScheme := detectCurrentColorScheme(c) | 16 | colorScheme := detectCurrentColorScheme(c) | ||
| 17 | fmt.Println("Color scheme detected:", colorScheme) | 17 | fmt.Println("Color scheme detected:", colorScheme) | ||
M internal/http/middlewares/detect-lang.go +2 -2
| @@ -10,8 +10,8 @@ import ( | |||
| 10 | 10 | // LangKey is a key for setting and getting the language from the context | |
| 11 | 11 | const LangKey = "CurrentLang" | |
| 12 | 12 | ||
| 13 | - | // LanguageDetectionMiddleware detects the current language and sets it in the context | |
| 14 | - | func LanguageDetectionMiddleware(next echo.HandlerFunc) echo.HandlerFunc { | |
| 13 | + | // LanguageDetectiondetects the current language and sets it in the context | |
| 14 | + | func LanguageDetection(next echo.HandlerFunc) echo.HandlerFunc { | |
| 15 | 15 | return func(c echo.Context) error { | |
| 16 | 16 | lang := detectCurrentLanguage(c) | |
| 17 | 17 | c.Set(LangKey, lang) | |
| @@ -10,8 +10,8 @@ import ( | |||||
| 10 | // LangKey is a key for setting and getting the language from the context | 10 | // LangKey is a key for setting and getting the language from the context | ||
| 11 | const LangKey = "CurrentLang" | 11 | const LangKey = "CurrentLang" | ||
| 12 | 12 | ||||
| 13 | - | // LanguageDetectionMiddleware detects the current language and sets it in the context | 13 | + | // LanguageDetectiondetects the current language and sets it in the context |
| 14 | - | func LanguageDetectionMiddleware(next echo.HandlerFunc) echo.HandlerFunc { | 14 | + | func LanguageDetection(next echo.HandlerFunc) echo.HandlerFunc { |
| 15 | return func(c echo.Context) error { | 15 | return func(c echo.Context) error { | ||
| 16 | lang := detectCurrentLanguage(c) | 16 | lang := detectCurrentLanguage(c) | ||
| 17 | c.Set(LangKey, lang) | 17 | c.Set(LangKey, lang) | ||
M internal/http/middlewares/logger.go +1 -1
| @@ -6,7 +6,7 @@ import ( | |||
| 6 | 6 | "github.com/rs/zerolog" | |
| 7 | 7 | ) | |
| 8 | 8 | ||
| 9 | - | func NewRequestLoggerMiddleware(logger zerolog.Logger) echo.MiddlewareFunc { | |
| 9 | + | func NewRequestLogger(logger zerolog.Logger) echo.MiddlewareFunc { | |
| 10 | 10 | return middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{ | |
| 11 | 11 | LogURI: true, | |
| 12 | 12 | LogStatus: true, | |
| @@ -6,7 +6,7 @@ import ( | |||||
| 6 | "github.com/rs/zerolog" | 6 | "github.com/rs/zerolog" | ||
| 7 | ) | 7 | ) | ||
| 8 | 8 | ||||
| 9 | - | func NewRequestLoggerMiddleware(logger zerolog.Logger) echo.MiddlewareFunc { | 9 | + | func NewRequestLogger(logger zerolog.Logger) echo.MiddlewareFunc { |
| 10 | return middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{ | 10 | return middleware.RequestLoggerWithConfig(middleware.RequestLoggerConfig{ | ||
| 11 | LogURI: true, | 11 | LogURI: true, | ||
| 12 | LogStatus: true, | 12 | LogStatus: true, | ||
M internal/http/middlewares/secure.go +1 -1
| @@ -5,7 +5,7 @@ import ( | |||
| 5 | 5 | "github.com/labstack/echo/v4/middleware" | |
| 6 | 6 | ) | |
| 7 | 7 | ||
| 8 | - | func SecureMiddleware() echo.MiddlewareFunc { | |
| 8 | + | func SecureRoutes() echo.MiddlewareFunc { | |
| 9 | 9 | return middleware.SecureWithConfig(middleware.SecureConfig{ | |
| 10 | 10 | XSSProtection: "1; mode=block", | |
| 11 | 11 | ContentTypeNosniff: "nosniff", | |
| @@ -5,7 +5,7 @@ import ( | |||||
| 5 | "github.com/labstack/echo/v4/middleware" | 5 | "github.com/labstack/echo/v4/middleware" | ||
| 6 | ) | 6 | ) | ||
| 7 | 7 | ||||
| 8 | - | func SecureMiddleware() echo.MiddlewareFunc { | 8 | + | func SecureRoutes() echo.MiddlewareFunc { |
| 9 | return middleware.SecureWithConfig(middleware.SecureConfig{ | 9 | return middleware.SecureWithConfig(middleware.SecureConfig{ | ||
| 10 | XSSProtection: "1; mode=block", | 10 | XSSProtection: "1; mode=block", | ||
| 11 | ContentTypeNosniff: "nosniff", | 11 | ContentTypeNosniff: "nosniff", | ||
M internal/http/routes/router.go +4 -3
| @@ -11,9 +11,10 @@ func ConfigureRouter(e *echo.Echo, app *app.App) *echo.Echo { | |||
| 11 | 11 | // The logger is already set in main.go, so we don't need to set it again here. | |
| 12 | 12 | ||
| 13 | 13 | // Register middlewares | |
| 14 | - | e.Use(middlewares.NewRequestLoggerMiddleware(app.HTTPLogger.Logger)) | |
| 15 | - | e.Use(middlewares.LanguageDetectionMiddleware) | |
| 16 | - | // e.Use(middlewares.SecureMiddleware()) // Uncomment this line to enable the secure middleware | |
| 14 | + | e.Use(middlewares.NewRequestLogger(app.HTTPLogger.Logger)) | |
| 15 | + | e.Use(middlewares.LanguageDetection) | |
| 16 | + | e.Use(middlewares.ColorSchemeDetection) | |
| 17 | + | //e.Use(middlewares.SecureMiddleware()) // Uncomment this line to enable the secure middleware | |
| 17 | 18 | // Register routes | |
| 18 | 19 | e = bindStaticAdminUI(e) | |
| 19 | 20 | ||
| @@ -11,9 +11,10 @@ func ConfigureRouter(e *echo.Echo, app *app.App) *echo.Echo { | |||||
| 11 | // The logger is already set in main.go, so we don't need to set it again here. | 11 | // The logger is already set in main.go, so we don't need to set it again here. | ||
| 12 | 12 | ||||
| 13 | // Register middlewares | 13 | // Register middlewares | ||
| 14 | - | e.Use(middlewares.NewRequestLoggerMiddleware(app.HTTPLogger.Logger)) | 14 | + | e.Use(middlewares.NewRequestLogger(app.HTTPLogger.Logger)) |
| 15 | - | e.Use(middlewares.LanguageDetectionMiddleware) | 15 | + | e.Use(middlewares.LanguageDetection) |
| 16 | - | // e.Use(middlewares.SecureMiddleware()) // Uncomment this line to enable the secure middleware | 16 | + | e.Use(middlewares.ColorSchemeDetection) |
| 17 | + | //e.Use(middlewares.SecureMiddleware()) // Uncomment this line to enable the secure middleware | |||
| 17 | // Register routes | 18 | // Register routes | ||
| 18 | e = bindStaticAdminUI(e) | 19 | e = bindStaticAdminUI(e) | ||
| 19 | 20 | ||||
D internal/ui/public/tmp/build-errors.log +0 -1
| @@ -1,1 +0,0 @@ | |||
| 1 | - | exit status 1⏎̸ | |
| @@ -1,1 +0,0 @@ | |||||
| 1 | - | exit status 1⏎̸ | |||