feat(cors): implement cors

This commit is contained in:
js0ny 2025-12-06 11:40:29 +00:00
parent 9e2b38e205
commit 15ad7a2fb7
2 changed files with 58 additions and 1 deletions

View file

@ -0,0 +1,27 @@
package io.github.js0ny.ilp_coursework.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* Global CORS configuration so the frontend running on a different port can call the REST API.
*/
@Configuration
public class CorsConfig implements WebMvcConfigurer {
private static final String[] ALLOWED_ORIGINS = new String[] {
"http://localhost:4173",
"http://127.0.0.1:4173",
"http://localhost:5173",
"http://127.0.0.1:5173"
};
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins(ALLOWED_ORIGINS)
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "PATCH")
.allowedHeaders("*");
}
}