Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package br.ufc.mandacaru5.config;
- import java.io.IOException;
- import javax.servlet.Filter;
- import javax.servlet.FilterChain;
- import javax.servlet.ServletException;
- import javax.servlet.ServletRequest;
- import javax.servlet.ServletResponse;
- import javax.servlet.annotation.WebFilter;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.springframework.core.Ordered;
- import org.springframework.core.annotation.Order;
- import org.springframework.stereotype.Component;
- @Component
- @Order(Ordered.HIGHEST_PRECEDENCE)
- @WebFilter("/*")
- public class CorsFilter implements Filter {
- public CorsFilter() {
- }
- @Override
- public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
- final HttpServletResponse response = (HttpServletResponse) res;
- response.setHeader("Access-Control-Allow-Origin", "*");
- response.setHeader("Access-Control-Allow-Methods", "*");
- response.setHeader("Access-Control-Allow-Headers", "*");
- if ("OPTIONS".equalsIgnoreCase(((HttpServletRequest) req).getMethod())) {
- response.setStatus(HttpServletResponse.SC_OK);
- } else {
- chain.doFilter(req, res);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement