-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: cors 허용 url pattern 프로파일화 (#443)
- Loading branch information
1 parent
f41238e
commit fa3b32e
Showing
5 changed files
with
25 additions
and
3 deletions.
There are no files selected for viewing
17 changes: 15 additions & 2 deletions
17
backend/src/main/java/com/woowacourse/zzimkkong/WebConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,30 @@ | ||
package com.woowacourse.zzimkkong; | ||
|
||
import org.apache.http.HttpHeaders; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
@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); | ||
// .allowedOriginPatterns("https://zzimkkong.com/"); | ||
.exposedHeaders(HttpHeaders.LOCATION) | ||
.allowedOriginPatterns(allowOriginUrlPatterns.toArray(new String[0])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule config
updated
from 2857e9 to 191932