I'm having this problem, As the picture illustrates.
I have two addresses in Ngrok (Free), one pointing to localhost:4200 (angular) And another pointing to localhost:8080 (Springboot).
So far so good. I put the front pointing to the Ngrok(Back) address to make the requests. POST works, but GET is not working.
It is giving CORS error. I've done everything and I still can't do it.
When I access the backend address through ngrok, it works.
On the first request it goes ok. But when you update the front it gives the error.
@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", "7200");
response.setHeader("Access-Control-Allow-Headers", "Origin, Authorization, Content-Type, xsrf-token, X-Requested-With, Accept, X-Auth-Token");
response.addHeader("Access-Control-Expose-Headers", "xsrf-token");
if ("OPTIONS".equals(request.getMethod())) {
response.setStatus(HttpServletResponse.SC_OK);
} else {
filterChain.doFilter(request, response);
}
}
}