Skip to content

Commit

Permalink
fix: CORS 설정 변경 (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitchannn authored Feb 29, 2024
1 parent 1c72f1a commit b2ad39a
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions server/src/main/java/sunflower/server/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
package sunflower.server.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import static org.springframework.http.HttpHeaders.LOCATION;

@Configuration
public class WebConfig implements WebMvcConfigurer {

public static final String HTTP_METHODS = "GET,HEAD,POST,PUT,DELETE,TRACE,OPTIONS,PATCH";
private static final String[] ALLOWED_ORIGINS = {"**"};

@Override
public void addCorsMappings(final CorsRegistry registry) {
registry.addMapping("*")
.allowedMethods(HTTP_METHODS.split(","))
.exposedHeaders(LOCATION);
registry.addMapping("/**")
.allowedOrigins(ALLOWED_ORIGINS)
.allowedOrigins("http://localhost:80")
.allowedMethods(
HttpMethod.GET.name(),
HttpMethod.POST.name(),
HttpMethod.PUT.name(),
HttpMethod.PATCH.name(),
HttpMethod.DELETE.name(),
HttpMethod.OPTIONS.name()
)
.allowedHeaders("*")
.exposedHeaders("Location")
.allowCredentials(true);
}
}

0 comments on commit b2ad39a

Please sign in to comment.