@Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest req = (HttpServletRequest) request;
        String path = trim(req.getRequestURI().substring(req.getContextPath().length()));
        // Would be better if we can put all the assets (other than index) under dist, so we can return real 404s
        // Currently this breaks the loading of the config file, though...
        if (resourceExists(path) && !path.isBlank()) {
            // If file exists, serve it up.
            if (path.endsWith(".json5") || path.endsWith(".json")) {
                String newResponse = configCache.computeIfAbsent(path, key -> parseAndSubstitute(request, key));
                response.setContentType("application/json");
                response.setContentLength(newResponse.length());
                response.getWriter().write(newResponse);
                response.flushBuffer();
            } else {
                chain.doFilter(request, response);
            }
        } else {
            // Else, send the spa index.
            req.getRequestDispatcher("/index.html").forward(req, response);
        }
    }
@author Marc Savy {@literal <marc@blackparrotlabs.io>}
portal/war/wildfly/src/main/java/io/apiman/portal/SplitterFilter.java