Skip to content

Commit

Permalink
refactor: cors 허락값 test
Browse files Browse the repository at this point in the history
  • Loading branch information
0702Yoon committed Aug 10, 2024
1 parent cdde55d commit 8263bdd
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,32 @@
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class CustomerCorsFilter implements Filter {
private final List<String> allowedOrigins = Arrays.asList(
"http://api.mju-bigbrother.xyz:3000",
"https://api.mju-bigbrother.xyz",
"http://localhost:8080",
"http://api.mju-bigbrother.xyz",
"http://api.mju-bigbrother.xyz:8080"
);

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;

response.setHeader("Access-Control-Allow-Origin", "http://api.mju-bigbrother.xyz:3000, http://localhost:8080");

String origin = request.getHeader("Origin");
if (allowedOrigins.contains(origin)) {
response.setHeader("Access-Control-Allow-Origin", origin);
}
// CORS 허용한 Origin
response.setHeader("Access-Control-Allow-Credentials", "true");
// 자격이 포함된 요청 받기
Expand Down

0 comments on commit 8263bdd

Please sign in to comment.