App creates a new instance of fiber.App
()
| 167 | |
| 168 | // App creates a new instance of fiber.App |
| 169 | func (container *Container) App() (app *fiber.App) { |
| 170 | if container.app != nil { |
| 171 | return container.app |
| 172 | } |
| 173 | |
| 174 | container.logger.Debug(fmt.Sprintf("creating %T", app)) |
| 175 | |
| 176 | app = fiber.New() |
| 177 | |
| 178 | // Health check endpoint registered before middleware for reliable Docker health checks |
| 179 | app.Get("/health", func(c fiber.Ctx) error { |
| 180 | return c.SendStatus(fiber.StatusOK) |
| 181 | }) |
| 182 | |
| 183 | app.Use(compress.New(compress.Config{ |
| 184 | Level: compress.LevelBestCompression, |
| 185 | })) |
| 186 | |
| 187 | if os.Getenv("USE_HTTP_LOGGER") == "true" { |
| 188 | app.Use(fiberLogger.New()) |
| 189 | } |
| 190 | |
| 191 | app.Use(otelfiber.Middleware()) |
| 192 | app.Use( |
| 193 | cors.New( |
| 194 | cors.Config{ |
| 195 | AllowOrigins: splitCommaEnv("CORS_ALLOW_ORIGINS", "*"), |
| 196 | AllowHeaders: splitCommaEnv("CORS_ALLOW_HEADERS", "*"), |
| 197 | AllowMethods: splitCommaEnv("CORS_ALLOW_METHODS", "GET,POST,PUT,DELETE,OPTIONS"), |
| 198 | AllowCredentials: false, |
| 199 | ExposeHeaders: splitCommaEnv("CORS_EXPOSE_HEADERS", "*"), |
| 200 | }, |
| 201 | ), |
| 202 | ) |
| 203 | app.Use(middlewares.HTTPRequestLogger(container.Tracer(), container.Logger())) |
| 204 | app.Use(middlewares.BearerAuth(container.Logger(), container.Tracer(), container.FirebaseAuthClient())) |
| 205 | app.Use(middlewares.APIKeyAuth(container.Logger(), container.Tracer(), container.UserRepository())) |
| 206 | |
| 207 | container.app = app |
| 208 | return app |
| 209 | } |
| 210 | |
| 211 | // BearerAPIKeyMiddleware creates a new instance of middlewares.BearerAPIKeyAuth |
| 212 | func (container *Container) BearerAPIKeyMiddleware() fiber.Handler { |
no test coverage detected