forked from maryem37/RagAndLoopVersionTestProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCorsConfig.java
More file actions
54 lines (43 loc) · 1.83 KB
/
Copy pathCorsConfig.java
File metadata and controls
54 lines (43 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package tn.enis.conge.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import java.util.Arrays;
import java.util.Collections;
/**
* CORS Configuration for allowing test requests
* Enables requests from testing frameworks and local clients
*/
@Configuration
public class CorsConfig {
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
// Allow all origins for testing (restrict in production!)
configuration.setAllowedOrigins(Arrays.asList(
"http://localhost:3000",
"http://localhost:8080",
"http://localhost:9000",
"http://localhost:9001",
"http://127.0.0.1:3000",
"http://127.0.0.1:8080",
"http://127.0.0.1:9000",
"http://127.0.0.1:9001"
));
// Allow all HTTP methods
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"));
// Allow headers
configuration.setAllowedHeaders(Collections.singletonList("*"));
// Allow credentials
configuration.setAllowCredentials(true);
// Expose headers
configuration.setExposedHeaders(Arrays.asList("Authorization", "Content-Type", "X-Total-Count"));
// Max age
configuration.setMaxAge(3600L);
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
}