-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUGFIX: Refactor CORS configuration to use externalized properties
Replaced hardcoded CORS configurations with a properties-based approach using `CorsProperties`. This centralizes management of allowed origins in application configuration files and improves flexibility for different environments. Updated both development and production YAML files to reflect the new structure.
- Loading branch information
Showing
3 changed files
with
27 additions
and
23 deletions.
There are no files selected for viewing
17 changes: 13 additions & 4 deletions
17
gateway-service/src/main/kotlin/com/michibaum/gatewayservice/config/CorsConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,30 @@ | ||
package com.michibaum.gatewayservice.config | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.context.annotation.Profile | ||
import org.springframework.web.servlet.config.annotation.EnableWebMvc | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer | ||
|
||
@Configuration | ||
@EnableWebMvc | ||
@Profile("dev") | ||
class CorsConfiguration: WebMvcConfigurer { | ||
@EnableConfigurationProperties(value = [CorsProperties::class]) | ||
class CorsConfiguration( | ||
private val corsProperties: CorsProperties | ||
): WebMvcConfigurer { | ||
|
||
override fun addCorsMappings(registry: org.springframework.web.servlet.config.annotation.CorsRegistry) { | ||
registry.addMapping("/**") | ||
.allowedMethods("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS") | ||
.allowedOrigins("http://michibaum.ch:4200", "http://michibaum.com:4200", "http://michibaum.eu:4200") | ||
.allowedOriginPatterns(*corsProperties.allowedOriginPatterns.toTypedArray()) | ||
.allowedHeaders("*") | ||
.allowCredentials(true) | ||
} | ||
|
||
} | ||
} | ||
|
||
@ConfigurationProperties(prefix = "cors") | ||
data class CorsProperties( | ||
val allowedOriginPatterns: List<String> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters