Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,18 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti

@Bean
//@Profile("dev")
CorsConfigurationSource corsConfigurationSource(@Value("${app.cors.allowed-origins}") String allowedOrigins) {
CorsConfigurationSource corsConfigurationSource(
@Value("${app.cors.allowed-origins}") List<String> allowedOrigins,
@Value("${app.cors.allowed-methods}") List<String> allowedMethods,
@Value("${app.cors.allowed-headers}") List<String> allowedHeaders) {

var config = new CorsConfiguration();
config.setAllowedOrigins(List.of(allowedOrigins));
config.setAllowedMethods(List.of("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
config.setAllowedHeaders(List.of("Authorization", "Content-Type", "x-requested-with"));
config.setAllowedOrigins(allowedOrigins);
config.setAllowedMethods(allowedMethods);
config.setAllowedHeaders(allowedHeaders);

var source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/api/ui/**", config);
source.registerCorsConfiguration("/api/**", config);
return source;
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ tenant-manager:

app:
cors:
allowed-origins: ${CORS_ALLOWED_ORIGIN:http://localhost:4200}
allowed-origins: ${CORS_ALLOWED_ORIGINS:http://localhost:4200}
allowed-methods: ${CORS_ALLOWED_METHODS:GET,POST,PUT,PATCH,DELETE,OPTIONS}
allowed-headers: ${CORS_ALLOWED_HEADERS:Authorization,Content-Type,x-requested-with}

---
# Development Profile with H2
Expand Down
4 changes: 3 additions & 1 deletion src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ spring:

app:
cors:
allowed-origins: "*"
allowed-origins: "*"
allowed-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
allowed-headers: Authorization,Content-Type,x-requested-with
Loading