Fixes Cors Configuration

This commit is contained in:
2022-11-15 15:28:47 -03:00
parent 536eef677b
commit 1c2fa9715d

View File

@@ -21,23 +21,15 @@ public class CorsConfig {
@Value("${com.hideyoshi.frontendConnectionType}") @Value("${com.hideyoshi.frontendConnectionType}")
private String CONNECTION_TYPE; private String CONNECTION_TYPE;
private final String HTTP = "http://";
private final String HTTPS = "https://";
@Bean @Bean
public CorsConfigurationSource corsConfigurationSource() { public CorsConfigurationSource corsConfigurationSource() {
String connectionProtocol = CONNECTION_TYPE.equals("secure")
? HTTPS
: HTTP;
CorsConfiguration configuration = new CorsConfiguration(); CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(List.of(connectionProtocol + FRONTEND_PATH)); configuration.setAllowedOrigins(List.of(FRONTEND_PATH));
configuration.setAllowedMethods(Collections.singletonList("*")); configuration.setAllowedMethods(Collections.singletonList("*"));
configuration.setAllowedHeaders(Collections.singletonList("*")); configuration.setAllowedHeaders(Collections.singletonList("*"));
// configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")); configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
// configuration.setAllowedHeaders(Arrays.asList("authorization", "content-type", "x-auth-token")); configuration.setAllowedHeaders(Arrays.asList("authorization", "content-type", "x-auth-token"));
configuration.setExposedHeaders(List.of("x-auth-token")); configuration.setExposedHeaders(List.of("x-auth-token"));
configuration.setAllowCredentials(true); configuration.setAllowCredentials(true);