forked from EnjoyTripKorea/EnjoyTripBackend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(EnjoyTripKorea#6) : CORS filter 구현
- Loading branch information
1 parent
d5d7c1c
commit 9e8f68e
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
EnjoyTripBackend/src/main/java/com/example/EnjoyTripBackend/filter/CorsFilter.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.EnjoyTripBackend.filter; | ||
|
||
import jakarta.servlet.*; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.io.IOException; | ||
|
||
@Slf4j | ||
public class CorsFilter implements Filter { | ||
|
||
public void init(FilterConfig filterConfig) throws ServletException {} | ||
|
||
public void destroy() {} | ||
|
||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { | ||
HttpServletResponse httpResponse = (HttpServletResponse) servletResponse; | ||
|
||
httpResponse.setHeader("Access-Control-Allow-Origin", "http://127.0.0.1:5500"); | ||
httpResponse.setHeader("Access-Control-Allow-Credentials", "true"); | ||
httpResponse.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS, GET, DELETE, PUT"); | ||
httpResponse.setHeader("Access-Control-Max-Age", "3600"); | ||
httpResponse.setHeader("Access-Control-Allow-Headers", "Authorization, x-requested-with, origin, content-type, accept"); | ||
chain.doFilter(servletRequest, servletResponse); | ||
} | ||
} |
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