CorsConfig.java
package com.student_loan.config;
// TODO Esta clase hay que cambiarla
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CorsConfig {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**") // Aplica a todas las rutas
.allowedOrigins("http://localhost:3000") // Permite solo el frontend
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // Métodos permitidos
.allowedHeaders("*") // Permitir todos los headers
.allowCredentials(true); // Permitir cookies/sesiones
}
};
}
}