Skip to content

Commit

Permalink
WIP - jakoś działa
Browse files Browse the repository at this point in the history
  • Loading branch information
JanisBe committed Apr 17, 2024
1 parent 5e260eb commit faf14e5
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/main/java/pl/janis/komornik/filter/SpaWebFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package pl.janis.komornik.filter;

import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.lang.NonNull;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;

public class SpaWebFilter extends OncePerRequestFilter {

/**
* Forwards any unmapped paths (except those containing a period) to the client {@code index.html}.
*/
@Override
protected void doFilterInternal(HttpServletRequest request, @NonNull HttpServletResponse response,
@NonNull FilterChain filterChain) throws ServletException, IOException {
String path = request.getRequestURI();
if (!path.startsWith("/api") &&
!path.startsWith("/login") &&
!path.startsWith("/auth") &&
!path.contains(".") &&
path.matches("/(.*)")) {
request.getRequestDispatcher("/index.html").forward(request, response);
return;
}

filterChain.doFilter(request, response);
}
}

0 comments on commit faf14e5

Please sign in to comment.