From 63c76790674c5d3f0945ef37ebbc5c0c65fd9ace Mon Sep 17 00:00:00 2001 From: Athou Date: Mon, 26 Aug 2024 00:17:42 +0200 Subject: [PATCH] make sure the webapp and openapi documentation are always up to date by preventing caching --- .../src/main/resources/application.properties | 8 +++++++ .../commafeed/integration/StaticFilesIT.java | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 commafeed-server/src/test/java/com/commafeed/integration/StaticFilesIT.java diff --git a/commafeed-server/src/main/resources/application.properties b/commafeed-server/src/main/resources/application.properties index adf6b324..1ca5fad9 100644 --- a/commafeed-server/src/main/resources/application.properties +++ b/commafeed-server/src/main/resources/application.properties @@ -2,6 +2,14 @@ quarkus.http.port=8082 quarkus.http.test-port=8085 +# static files +## make sure the webapp is always up to date +quarkus.http.filter.index-html.header."Cache-Control"=no-cache, no-store, must-revalidate +quarkus.http.filter.index-html.matches=/ +## make sure the openapi documentation is always up to date +quarkus.http.filter.openapi.header."Cache-Control"=no-cache, no-store, must-revalidate +quarkus.http.filter.openapi.matches=/openapi[.](json|yaml) + # security quarkus.http.auth.basic=true quarkus.http.auth.form.enabled=true diff --git a/commafeed-server/src/test/java/com/commafeed/integration/StaticFilesIT.java b/commafeed-server/src/test/java/com/commafeed/integration/StaticFilesIT.java new file mode 100644 index 00000000..b16495ec --- /dev/null +++ b/commafeed-server/src/test/java/com/commafeed/integration/StaticFilesIT.java @@ -0,0 +1,23 @@ +package com.commafeed.integration; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; + +@QuarkusTest +class StaticFilesIT { + + @ParameterizedTest + @ValueSource(strings = { "/", "/openapi.json", "/openapi.yaml" }) + void servedWithoutCache(String path) { + RestAssured.given().when().get(path).then().statusCode(200).header("Cache-Control", "no-cache, no-store, must-revalidate"); + } + + @ParameterizedTest + @ValueSource(strings = { "/favicon.ico" }) + void servedWithCache(String path) { + RestAssured.given().when().get(path).then().statusCode(200).header("Cache-Control", "public, immutable, max-age=86400"); + } +}