# CorsConfig.java

    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("*");
        }
    }