| | 148 | === CORS |
| | 149 | * The application uses a CORS configuration to control which frontend clients are allowed to communicate with the backend API. In development, requests are allowed only from local frontend origins such as http://localhost:*(this will be changed to the correct URL of the hosted site). The configuration defines the permitted HTTP methods, including GET, POST, PUT, PATCH, DELETE, and OPTIONS. |
| | 150 | {{{ |
| | 151 | @Bean |
| | 152 | public CorsConfigurationSource corsConfigurationSource() { |
| | 153 | CorsConfiguration configuration = new CorsConfiguration(); |
| | 154 | configuration.setAllowedOriginPatterns(List.of("http://localhost:*")); |
| | 155 | configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT","PATCH", "DELETE", "OPTIONS")); |
| | 156 | configuration.setAllowedHeaders(Arrays.asList("*")); |
| | 157 | configuration.setAllowCredentials(true); |
| | 158 | |
| | 159 | UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
| | 160 | source.registerCorsConfiguration("/**", configuration); |
| | 161 | return source; |
| | 162 | } |
| | 163 | }}} |