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

cors3 #21

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
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
23 changes: 0 additions & 23 deletions src/main/java/umc/beanstalk/config/CorsConfig.java

This file was deleted.

34 changes: 34 additions & 0 deletions src/main/java/umc/beanstalk/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package umc.beanstalk.config;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

private final List<String> allowOriginUrlPatterns;

public WebConfig(@Value("${cors.allow-origin.urls}") String allowOriginUrlPatterns) {
this.allowOriginUrlPatterns = Stream.of(allowOriginUrlPatterns.split(","))
.map(String::strip)
.collect(Collectors.toList());
}

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedMethods("*")
.exposedHeaders(HttpHeaders.LOCATION)
.allowedHeaders("Authorization", "Content-Type")
.allowCredentials(true)
.allowedOriginPatterns(allowOriginUrlPatterns.toArray(new String[0]))
.maxAge(3600);
}
}
3 changes: 3 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ cloud:
secretKey: ${AWS_SECRET_ACCESS_KEY}


cors:
allow-origin:
urls: "*"
Loading