Created
February 6, 2019 19:02
-
-
Save romanoffs/93d3215567b125de366059fe35c55660 to your computer and use it in GitHub Desktop.
Forward Request for Angular 2x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
@Order(Ordered.HIGHEST_PRECEDENCE) | |
public class Forward extends OncePerRequestFilter { | |
private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |
@Override | |
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) | |
throws IOException, ServletException { | |
String uri = request.getRequestURI(); | |
String contextPath = request.getContextPath(); | |
if (!uri.startsWith(contextPath + "/api") && | |
!uri.startsWith(contextPath + "/assets") && | |
!uri.equals(contextPath) && | |
// only forward if there's no file extension (exclude *.js, *.css etc) | |
uri.matches("^([^.]+)$")) { | |
logger.debug("Forward Request filter '{}'", request.getRequestURL()); | |
RequestDispatcher dispatcher = request.getRequestDispatcher("/"); | |
dispatcher.forward(request, response); | |
return; | |
} | |
chain.doFilter(request, response); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment