fix(backend): fixed cors error on build dev environment

This commit is contained in:
Bernhard Müller 2026-07-27 18:16:12 +02:00
parent 67e1ed144f
commit 3edf5cc41c
2 changed files with 4 additions and 8 deletions

View File

@ -30,7 +30,6 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
@Configuration @Configuration
@EnableWebSecurity @EnableWebSecurity
@ -94,7 +93,7 @@ public class SecurityConfig {
CorsConfiguration configuration = new CorsConfiguration(); CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Arrays.stream(corsOrigins.split(",")).map(String::trim).toList()); configuration.setAllowedOrigins(Arrays.stream(corsOrigins.split(",")).map(String::trim).toList());
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH")); configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"));
configuration.setAllowedHeaders(Arrays.asList("Authorization", "Content-Type")); configuration.setAllowedHeaders(Arrays.asList("Authorization", "Content-Type", "X-Access-Token"));
configuration.setAllowCredentials(true); configuration.setAllowCredentials(true);
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration); source.registerCorsConfiguration("/**", configuration);

View File

@ -3,14 +3,11 @@ import {HttpInterceptorFn} from '@angular/common/http';
export const jwtInterceptor: HttpInterceptorFn = (req, next) => { export const jwtInterceptor: HttpInterceptorFn = (req, next) => {
const token = localStorage.getItem('token'); const token = localStorage.getItem('token');
// If a token exists, clone the request and add the Authorization header
if (token) { if (token) {
const clonedRequest = req.clone({ const authReq = req.clone({
setHeaders: { headers: req.headers.set('X-Access-Token', token)
Authorization: `Bearer ${token}`
}
}); });
return next(clonedRequest); return next(authReq);
} }
return next(req); return next(req);