-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |