Skip to content

Commit

Permalink
fix: update CorsConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
limjustin committed Jun 2, 2024
1 parent 0e281fc commit e18156d
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/main/java/dev/goormthon/ppoori/global/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package dev.goormthon.ppoori.global.config;

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;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@Configuration
public class WebConfig implements WebMvcConfigurer {
public class WebConfig {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/api/**")
.allowedOrigins("https://jejucart-front.vercel.app", "http://localhost:3000", "https://ppoori.shop/api/v1/docs")
.allowedMethods("HEAD", "OPTIONS", "GET", "POST", "PUT", "PATCH", "DELETE")
.allowCredentials(true);
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOriginPattern("*");
config.addAllowedHeader("*");
config.addAllowedMethod("*");

source.registerCorsConfiguration("/api/**", config);
return new CorsFilter(source);
}
}

0 comments on commit e18156d

Please sign in to comment.