Skip to content

Instantly share code, notes, and snippets.

@arleighdickerson
Created July 13, 2025 18:14
Show Gist options
  • Save arleighdickerson/f8b1d16c657d0973382b8add6ce0fd5e to your computer and use it in GitHub Desktop.
Save arleighdickerson/f8b1d16c657d0973382b8add6ce0fd5e to your computer and use it in GitHub Desktop.
import lombok.val;
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
class IndexDotHtmlFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(
HttpServletRequest request,
HttpServletResponse response,
FilterChain filterChain
) throws ServletException, IOException {
val path = request.getRequestURI().substring(request.getContextPath().length());
if (
!path.startsWith("/api") &&
!path.startsWith("/wss") &&
!path.startsWith("/ctl") &&
!path.contains(".") &&
path.matches("/(.*)")
) {
request.getRequestDispatcher("/index.html").forward(request, response);
} else {
filterChain.doFilter(request, response);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment