Answer the question
In order to leave comments, you need to log in
How to fix redirect error (CORS)?
There is a bunch of Angular (frontend) + Nginx (proxy) + Spring (backend)
And there is one condition under which the filter works on the backend
public class MyFilter implements Filter {
//...
HttpServlerResponse response = (HttpServletResponse) servletResponse;
response.sendRedirect("http://yandex.ru");
//...
}
Answer the question
In order to leave comments, you need to log in
Add a filter like this:
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class CorsFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
httpServletResponse.setHeader("Access-Control-Allow-Origin", httpServletRequest.getHeader("Origin"));
httpServletResponse.setHeader("Access-Control-Max-Age", "3600");
if (!"OPTIONS".equalsIgnoreCase(httpServletRequest.getMethod())) {
chain.doFilter(request, response);
}
}
@Override
public void init(FilterConfig filterConfig) {
}
@Override
public void destroy() {
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question