in src/api-server/src/main/java/com/google/abmedge/apiserver/configuration/RedirectFilterConfiguration.java [58:86]
private OncePerRequestFilter createRedirectFilter() {
//noinspection NullableProblems
return new OncePerRequestFilter() {
// Forwards all routes except '/index.html', '/200.html', '/favicon.ico', '/sw.js' '/api/',
// '/api/**'
private final String REGEX =
"(?!/actuator|/api|/_nuxt|/static|/index\\.html|/200\\.html|/favicon\\.ico|/sw\\.js).*$";
private final Pattern pattern = Pattern.compile(REGEX);
@Override
protected void doFilterInternal(
HttpServletRequest req, HttpServletResponse res, FilterChain chain)
throws ServletException, IOException {
String uri = req.getRequestURI();
if (pattern.matcher(uri).matches() && !uri.equals("/")) {
// Delegate/Forward to `/` if `pattern` matches and it is not `/`
// Read: https://github.com/jonashackt/spring-boot-vuejs#using-history-mode-for-nicer-urls
if (!uri.endsWith("/ready") && !uri.endsWith("/healthy")) {
// skip logging kube-proxy checks on /ready and /healthy
LOGGER.info("URL {} entered directly into the Browser, redirecting...", uri);
}
RequestDispatcher rd = req.getRequestDispatcher("/");
rd.forward(req, res);
} else {
chain.doFilter(req, res);
}
}
};
}