Skip to content

Commit

Permalink
Ensure that index.html works in any directory in native mode
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Apr 5, 2024
1 parent ce368d4 commit 1854afd
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,15 @@ public void nativeImageResource(Optional<StaticResourcesBuildItem> staticResourc
// TODO: do we perhaps want to register the whole directory?
continue;
}
String metaInfResourcesPath = StaticResourcesRecorder.META_INF_RESOURCES + entry.getPath();
String path = entry.getPath();
int index = path.lastIndexOf("/index.html");
if (index > 0) {
// in this case we want to register the directory that contains index.html (for example static/users/index.html would register static/users)
// as a resource because the StaticHandler needs to see the directory is available in order to serve index.html
producer.produce(new NativeImageResourceBuildItem(
StaticResourcesRecorder.META_INF_RESOURCES + path.substring(0, index)));
}
String metaInfResourcesPath = StaticResourcesRecorder.META_INF_RESOURCES + path;
metaInfResources.add(metaInfResourcesPath);
}
producer.produce(new NativeImageResourceBuildItem(metaInfResources));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
<head>
<title>Hello world</title></head>
<body>
Hello World
</body>
</html>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.quarkus.it.vertx;

import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
public class StaticResourcesIT extends StaticResourcesTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.quarkus.it.vertx;

import static io.restassured.RestAssured.when;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class StaticResourcesTest {

@Test
public void testExisting() {
when().get("/test.txt").then().statusCode(200);
}

@Test
public void testNonExisting() {
when().get("/test2.txt").then().statusCode(404);
}

@Test
public void testIndexInDirectory() {
when().get("/dummy/").then().statusCode(200);
}

@Test
public void testNonIndexInDirectory() {
when().get("/dummy2/").then().statusCode(404);
}

@Test
public void testIndexInNonExistingDirectory() {
when().get("/dummy3/").then().statusCode(404);
}
}

0 comments on commit 1854afd

Please sign in to comment.