Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion api/pkg/di/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ func NewContainer(projectID string, version string) (container *Container) {
return container
}

func GetEnvWithDefault(key, defaultValue string) string {
value := os.Getenv(key)
if value == "" {
return defaultValue
}

return value
}

// App creates a new instance of fiber.App
func (container *Container) App() (app *fiber.App) {
if container.app != nil {
Expand All @@ -168,7 +177,15 @@ func (container *Container) App() (app *fiber.App) {
}

app.Use(otelfiber.Middleware())
app.Use(cors.New())
app.Use(cors.New(
cors.Config{
AllowOrigins: GetEnvWithDefault("CORS_ALLOW_ORIGINS", "*"),
AllowHeaders: GetEnvWithDefault("CORS_ALLOW_HEADERS", "*"),
AllowMethods: GetEnvWithDefault("CORS_ALLOW_METHODS", "GET,POST,PUT,DELETE,OPTIONS"),
AllowCredentials: false,
ExposeHeaders: GetEnvWithDefault("CORS_EXPOSE_HEADERS", "*"),
}))

app.Use(middlewares.HTTPRequestLogger(container.Tracer(), container.Logger()))

app.Use(middlewares.BearerAuth(container.Logger(), container.Tracer(), container.FirebaseAuthClient()))
Expand Down