()
| 14 | var DEV_MODES = []string{"main", "test", "development"} |
| 15 | |
| 16 | func (app *BootstrapApp) setupRouter() (*gin.Engine, error) { |
| 17 | if !slices.Contains(DEV_MODES, config.Version) { |
| 18 | gin.SetMode(gin.ReleaseMode) |
| 19 | } |
| 20 | |
| 21 | engine := gin.New() |
| 22 | engine.Use(gin.Recovery()) |
| 23 | |
| 24 | if len(app.config.Auth.TrustedProxies) > 0 { |
| 25 | err := engine.SetTrustedProxies(app.config.Auth.TrustedProxies) |
| 26 | |
| 27 | if err != nil { |
| 28 | return nil, fmt.Errorf("failed to set trusted proxies: %w", err) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | contextMiddleware := middleware.NewContextMiddleware(middleware.ContextMiddlewareConfig{ |
| 33 | CookieDomain: app.context.cookieDomain, |
| 34 | }, app.services.authService, app.services.oauthBrokerService) |
| 35 | |
| 36 | err := contextMiddleware.Init() |
| 37 | |
| 38 | if err != nil { |
| 39 | return nil, fmt.Errorf("failed to initialize context middleware: %w", err) |
| 40 | } |
| 41 | |
| 42 | engine.Use(contextMiddleware.Middleware()) |
| 43 | |
| 44 | uiMiddleware := middleware.NewUIMiddleware() |
| 45 | |
| 46 | err = uiMiddleware.Init() |
| 47 | |
| 48 | if err != nil { |
| 49 | return nil, fmt.Errorf("failed to initialize UI middleware: %w", err) |
| 50 | } |
| 51 | |
| 52 | engine.Use(uiMiddleware.Middleware()) |
| 53 | |
| 54 | zerologMiddleware := middleware.NewZerologMiddleware() |
| 55 | |
| 56 | err = zerologMiddleware.Init() |
| 57 | |
| 58 | if err != nil { |
| 59 | return nil, fmt.Errorf("failed to initialize zerolog middleware: %w", err) |
| 60 | } |
| 61 | |
| 62 | engine.Use(zerologMiddleware.Middleware()) |
| 63 | |
| 64 | apiRouter := engine.Group("/api") |
| 65 | |
| 66 | contextController := controller.NewContextController(controller.ContextControllerConfig{ |
| 67 | Providers: app.context.configuredProviders, |
| 68 | Title: app.config.UI.Title, |
| 69 | AppURL: app.config.AppURL, |
| 70 | CookieDomain: app.context.cookieDomain, |
| 71 | ForgotPasswordMessage: app.config.UI.ForgotPasswordMessage, |
| 72 | BackgroundImage: app.config.UI.BackgroundImage, |
| 73 | OAuthAutoRedirect: app.config.OAuth.AutoRedirect, |
no test coverage detected