chore(BE): update response code for docs & signin page (#23140)

This commit is contained in:
Chirag Madlani 2025-08-29 10:59:22 +05:30 committed by GitHub
parent 29bf750bde
commit c41828ece0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,15 +21,19 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import org.jetbrains.annotations.Nullable;
import org.openmetadata.service.config.OMWebConfiguration;
import org.openmetadata.service.resources.system.IndexResource;
public class OpenMetadataAssetServlet extends AssetServlet {
private final OMWebConfiguration webConfiguration;
private final String basePath;
// List of frontend paths that should be whitelisted and serve the index file
private static final List<String> WHITELISTED_PATHS = Arrays.asList("/docs", "/signin");
public OpenMetadataAssetServlet(
String basePath,
String resourcePath,
@ -57,8 +61,31 @@ public class OpenMetadataAssetServlet extends AssetServlet {
}
super.doGet(req, resp);
// Check if response is 404 and the path should be whitelisted
if (!resp.isCommitted() && (resp.getStatus() == 404)) {
if (isWhitelistedPath(requestUri)) {
// Serve index file for whitelisted paths instead of 404
resp.setStatus(200);
resp.setContentType("text/html");
resp.getWriter().write(IndexResource.getIndexFile(this.basePath));
} else {
resp.sendError(404);
}
}
}
/**
* Check if the given URI path should be whitelisted
* @param requestUri The request URI to check
* @return true if the path should be whitelisted, false otherwise
*/
private boolean isWhitelistedPath(String requestUri) {
for (String whitelistedPath : WHITELISTED_PATHS) {
if (requestUri.startsWith(whitelistedPath)) {
return true;
}
}
return false;
}
}