Skip to content

Commit f24a32a

Browse files
authored
Merge pull request #641 from Apex-Network-NG/main
Add cors config for seperate backend urls
2 parents dc2cb99 + 9d7f8e5 commit f24a32a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

api/pkg/di/container.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ func NewContainer(projectID string, version string) (container *Container) {
153153
return container
154154
}
155155

156+
func GetEnvWithDefault(key, defaultValue string) string {
157+
value := os.Getenv(key)
158+
if value == "" {
159+
return defaultValue
160+
}
161+
162+
return value
163+
}
164+
156165
// App creates a new instance of fiber.App
157166
func (container *Container) App() (app *fiber.App) {
158167
if container.app != nil {
@@ -168,7 +177,15 @@ func (container *Container) App() (app *fiber.App) {
168177
}
169178

170179
app.Use(otelfiber.Middleware())
171-
app.Use(cors.New())
180+
app.Use(cors.New(
181+
cors.Config{
182+
AllowOrigins: GetEnvWithDefault("CORS_ALLOW_ORIGINS", "*"),
183+
AllowHeaders: GetEnvWithDefault("CORS_ALLOW_HEADERS", "*"),
184+
AllowMethods: GetEnvWithDefault("CORS_ALLOW_METHODS", "GET,POST,PUT,DELETE,OPTIONS"),
185+
AllowCredentials: false,
186+
ExposeHeaders: GetEnvWithDefault("CORS_EXPOSE_HEADERS", "*"),
187+
}))
188+
172189
app.Use(middlewares.HTTPRequestLogger(container.Tracer(), container.Logger()))
173190

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

0 commit comments

Comments
 (0)