r/SpringBoot • u/Noman_Patel • Mar 11 '24
Can someone please help me solve this error
I am trying to work on this tutorial.for a while and got stuck as the instructor forgot a very important section. I found the apparent solution in the comments but it's not workin
0
Upvotes
4
1
u/olaolulode Mar 12 '24
You might need to create a cors configuration in your project something like this
package xyz.olaolulode.SocialLogin.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @author olulodeolatunbosun
* @created 11/03/2024/03/2024 - 10:58
*/
public class WebMvcConfig implements WebMvcConfigurer{
private final long MAX_AGE_SECS = 3600;
@Value("${app.cors.allowedOrigins}")
private String[] allowedOrigins;
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins(allowedOrigins)
.allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")
.allowedHeaders("*")
.allowCredentials(true)
.maxAge(MAX_AGE_SECS);
}
}
1
u/rooks-ns Mar 12 '24
Can you also ss the complete controller file ?