summaryrefslogtreecommitdiff
path: root/clams-server/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'clams-server/src/main/java')
-rw-r--r--clams-server/src/main/java/no/eliashaugsbakk/clams/server/config/AppRoutes.java19
1 files changed, 16 insertions, 3 deletions
diff --git a/clams-server/src/main/java/no/eliashaugsbakk/clams/server/config/AppRoutes.java b/clams-server/src/main/java/no/eliashaugsbakk/clams/server/config/AppRoutes.java
index b296f4f..4676165 100644
--- a/clams-server/src/main/java/no/eliashaugsbakk/clams/server/config/AppRoutes.java
+++ b/clams-server/src/main/java/no/eliashaugsbakk/clams/server/config/AppRoutes.java
@@ -23,9 +23,10 @@ public class AppRoutes implements EndpointGroup {
before(ctx -> {
String path = ctx.path();
- // Skip non-GET requests and API endpoints
+ // Skip non-GET requests, API endpoints, static resources, and queried requests
if (!ctx.method().name().equalsIgnoreCase("GET")
|| path.startsWith("/api")
+ || isStaticResource(path)
|| ctx.queryString() != null) {
return;
}
@@ -51,11 +52,15 @@ public class AppRoutes implements EndpointGroup {
return;
}
- // 2. Cache GET responses
+ // 2. Cache GET responses for HTML pages
+ String contentType = ctx.contentType();
if (method.equalsIgnoreCase("GET")
&& !path.startsWith("/api") // exclude API responses
+ && !isStaticResource(path) // exclude static assets
&& ctx.queryString() == null // exclude queried pages
- && ctx.status().getCode() == 200) { // only cache successful responses
+ && ctx.status().getCode() == 200
+ && contentType != null
+ && contentType.contains("text/html")) { // only cache HTML responses
String renderedHtml = ctx.result();
if (renderedHtml != null && !renderedHtml.isBlank()) {
@@ -110,4 +115,12 @@ public class AppRoutes implements EndpointGroup {
delete("media/{uuid}", appContext.getMediaController()::handleDeleteMedia);
});
}
+
+ private static boolean isStaticResource(String path) {
+ if (path == null) {
+ return false;
+ }
+ return path.startsWith("/css/")
+ || path.startsWith("/images/");
+ }
}