diff --git a/pom.xml b/pom.xml index bf55202..ba3fe27 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ 4.0.0 org.teapot teapot-backend - 3.0.0 + 3.0.1 jar diff --git a/src/main/java/org/teapot/backend/config/CorsFilter.java b/src/main/java/org/teapot/backend/config/CorsFilter.java new file mode 100644 index 0000000..54146dd --- /dev/null +++ b/src/main/java/org/teapot/backend/config/CorsFilter.java @@ -0,0 +1,27 @@ +package org.teapot.backend.config; + +import org.springframework.stereotype.Component; +import org.springframework.web.filter.OncePerRequestFilter; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@Component +public class CorsFilter extends OncePerRequestFilter { + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) + throws ServletException, IOException { + response.setHeader("Access-Control-Allow-Origin", "*"); + response.setHeader("Access-Control-Allow-Methods", + "POST, GET, PATCH, DELETE, OPTIONS"); + response.setHeader("Access-Control-Max-Age", "3600"); + response.setHeader("Access-Control-Allow-Headers", + "x-requested-with, Content-Type, Authorization, Accept"); + + filterChain.doFilter(request, response); + } +}