Skip to content

Commit

Permalink
do not redirect API requests to UI status page
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Otto committed Nov 2, 2023
1 parent dfbf38d commit fc70667
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@ public boolean preHandle(
) throws Exception {
StatusModel status = statusService.getStatus();
String path = request.getServletPath();
if (!status.synced() && !isResource(path) && !isStatusPage(path)) {
response.sendRedirect("/status");
return false;
if (disallowRedirect(status, path)) {
return true;
}
return true;
response.sendRedirect("/status");
return false;
}

private boolean disallowRedirect(StatusModel status, String path) {
if (status.synced()) {
return true;
}
return isResource(path) || isStatusPage(path) || isApi(path);
}

boolean isStatusPage(@Nullable String path) {
Expand All @@ -42,6 +49,10 @@ boolean isResource(@Nullable String path) {
return path != null && (path.contains("/css/") || path.contains("/js/") || path.contains("/images/"));
}

boolean isApi(@Nullable String path) {
return path != null && (path.contains("/api/") || path.contains("/legacy/"));
}

@Override
public void postHandle(
HttpServletRequest request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ void preHandle_cssResource_noRedirect() throws Exception {
preHandleStatusNotSyncedExpectNoRedirect("/css/main.css");
}

@Test
void preHandle_api_noRedirect() throws Exception {
preHandleStatusNotSyncedExpectNoRedirect("/api/foo/bar");
}

@Test
void preHandle_legacy_api_noRedirect() throws Exception {
preHandleStatusNotSyncedExpectNoRedirect("/legacy/foo/bar");
}

@Test
void preHandle_jsResource_noRedirect() throws Exception {
preHandleStatusNotSyncedExpectNoRedirect("/js/main.js");
Expand Down

0 comments on commit fc70667

Please sign in to comment.