Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: CORS 설정 변경 #67

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}