Class SpaRoutingFilter

java.lang.Object
ru.vyarus.guicey.spa.filter.SpaRoutingFilter
All Implemented Interfaces:
jakarta.servlet.Filter

public class SpaRoutingFilter extends Object implements jakarta.servlet.Filter
Filter must be mapped to assets servlet, serving spa application. Bypass all calls to servlet, but if servlet returns 404, tries to redirect to application main page.

This is important to properly handle html5 client routing (without hashbang).

In order to route, filter checks request accept header: if it's compatible with "text/html" - routing is performed. If not, 404 error sent. Also, regex pattern is used to prevent routing (for example, for html templates). This is important for all other assets, which absence must be indicated.

Since:
02.04.2017
  • Constructor Details

    • SpaRoutingFilter

      public SpaRoutingFilter(String target, String noRedirectRegex)
      Create SPA filter.
      Parameters:
      target - application root
      noRedirectRegex - non-SPA routes detection regex
  • Method Details

    • init

      public void init(jakarta.servlet.FilterConfig filterConfig) throws jakarta.servlet.ServletException
      Specified by:
      init in interface jakarta.servlet.Filter
      Throws:
      jakarta.servlet.ServletException
    • doFilter

      public void doFilter(jakarta.servlet.ServletRequest servletRequest, jakarta.servlet.ServletResponse servletResponse, jakarta.servlet.FilterChain chain) throws IOException, jakarta.servlet.ServletException
      Specified by:
      doFilter in interface jakarta.servlet.Filter
      Throws:
      IOException
      jakarta.servlet.ServletException
    • destroy

      public void destroy()
      Specified by:
      destroy in interface jakarta.servlet.Filter