content: package com.mcda.database.project.demo;
  
  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", "GET, POST, PUT, DELETE, OPTIONS");
          response.setHeader("Access-Control-Max-Age", "3600");
          response.setHeader("Access-Control-Allow-Headers", "authorization, content-type, xsrf-token,access-control-allow-origin");
          response.addHeader("Access-Control-Expose-Headers", "xsrf-token");
          if ("OPTIONS".equals(request.getMethod())) {
              response.setStatus(HttpServletResponse.SC_OK);
          } else { 
              filterChain.doFilter(request, response);
          }
      }
  }