mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-05-10 14:28:12 +00:00
4f7335ed73
* feat: add new logger * refactor: use one struct for context handling and cancellation * refactor: rework logging and config in controllers * refactor: rework logging and config in middlewares * refactor: rework logging and cancellation in services * refactor: rework cli logging * fix: improve logging in routines * feat: use sync groups for better cancellation * refactor: simplify middleware, controller and service init * tests: fix controller tests * tests: use require instead of assert where previous step is required * tests: fix middleware tests * tests: fix service tests * tests: fix context tests * fix: fix typos * feat: add option to enable or disable concurrent listeners * fix: assign public key correctly in oidc server * tests: fix don't try to test logger with char size * fix: coderabbit comments * tests: use filepath join instead of path join * fix: ensure unix socket shutdown doesn't run twice * chore: remove temp lint file
56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
package bootstrap
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/tinyauthapp/tinyauth/internal/controller"
|
|
"github.com/tinyauthapp/tinyauth/internal/middleware"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func (app *BootstrapApp) setupRouter() error {
|
|
// we don't want gin debug mode
|
|
gin.SetMode(gin.ReleaseMode)
|
|
|
|
engine := gin.New()
|
|
engine.Use(gin.Recovery())
|
|
|
|
if len(app.config.Auth.TrustedProxies) > 0 {
|
|
err := engine.SetTrustedProxies(app.config.Auth.TrustedProxies)
|
|
|
|
if err != nil {
|
|
return fmt.Errorf("failed to set trusted proxies: %w", err)
|
|
}
|
|
}
|
|
|
|
contextMiddleware := middleware.NewContextMiddleware(app.log, app.runtime, app.services.authService, app.services.oauthBrokerService)
|
|
engine.Use(contextMiddleware.Middleware())
|
|
|
|
uiMiddleware, err := middleware.NewUIMiddleware()
|
|
|
|
if err != nil {
|
|
return fmt.Errorf("failed to initialize UI middleware: %w", err)
|
|
}
|
|
|
|
engine.Use(uiMiddleware.Middleware())
|
|
|
|
zerologMiddleware := middleware.NewZerologMiddleware(app.log)
|
|
|
|
engine.Use(zerologMiddleware.Middleware())
|
|
|
|
apiRouter := engine.Group("/api")
|
|
|
|
controller.NewContextController(app.log, app.config, app.runtime, apiRouter)
|
|
controller.NewOAuthController(app.log, app.config, app.runtime, apiRouter, app.services.authService)
|
|
controller.NewOIDCController(app.log, app.services.oidcService, app.runtime, apiRouter)
|
|
controller.NewProxyController(app.log, app.runtime, apiRouter, app.services.accessControlService, app.services.authService)
|
|
controller.NewUserController(app.log, app.runtime, apiRouter, app.services.authService)
|
|
controller.NewResourcesController(app.config, &engine.RouterGroup)
|
|
controller.NewHealthController(apiRouter)
|
|
controller.NewWellKnownController(app.services.oidcService, &engine.RouterGroup)
|
|
|
|
app.router = engine
|
|
return nil
|
|
}
|