Skip to content

Commit c198007

Browse files
ia3andygsmet
authored andcommitted
Fix native image generated static resources index
(cherry picked from commit 22a264d)
1 parent 6d443d8 commit c198007

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

extensions/vertx-http/deployment-spi/src/main/java/io/quarkus/vertx/http/deployment/spi/GeneratedStaticResourceBuildItem.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* {@link AdditionalStaticResourceBuildItem}, {@link NativeImageResourceBuildItem}
1919
* and {@link io.quarkus.deployment.builditem.GeneratedResourceBuildItem} build items.
2020
* <br>
21-
* The value of {@code endpoint} should be prefixed with {@code '/'}.
21+
* The value of {@code endpoint} should be prefixed with {@code '/'} and reference a file (no trailing `/`).
2222
*/
2323
public final class GeneratedStaticResourceBuildItem extends MultiBuildItem {
2424

@@ -28,8 +28,14 @@ public final class GeneratedStaticResourceBuildItem extends MultiBuildItem {
2828
private final byte[] content;
2929

3030
private GeneratedStaticResourceBuildItem(final String endpoint, final byte[] content, final Path file) {
31-
if (!requireNonNull(endpoint, "endpoint is required").startsWith("/")) {
32-
throw new IllegalArgumentException("endpoint must start with '/'");
31+
requireNonNull(endpoint, "endpoint is required");
32+
if (!endpoint.startsWith("/")) {
33+
throw new IllegalArgumentException(
34+
"GeneratedStaticResourceBuildItem endpoint must start with '/': %s".formatted(endpoint));
35+
}
36+
if (endpoint.endsWith("/")) {
37+
throw new IllegalArgumentException(
38+
"GeneratedStaticResourceBuildItem endpoint must not end with '/': %s".formatted(endpoint));
3339
}
3440
this.endpoint = endpoint;
3541
this.file = file;

extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/GeneratedStaticResourcesProcessor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ public void produceResources(List<GeneratedStaticResourceBuildItem> generatedSta
7373
additionalStaticResourcesProducer.produce(
7474
new AdditionalStaticResourceBuildItem(generatedStaticResource.getEndpoint(), false));
7575
nativeImageResourcesProducer.produce(new NativeImageResourceBuildItem(generatedStaticResourceLocation));
76+
int lastSep = generatedStaticResourceLocation.lastIndexOf('/');
77+
if (lastSep > 0) {
78+
String parent = generatedStaticResourceLocation.substring(0, lastSep);
79+
// if the resource is somehow an index page, we need the parent directory to also be added as a native resource so that we can resolve both `/path/index.html` and `/path/` (needed by Vert.x static handler).
80+
nativeImageResourcesProducer.produce(new NativeImageResourceBuildItem(parent));
81+
}
7682
}
7783
}
7884
}

0 commit comments

Comments
 (0)