Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added documentation on Serve static resources not defined at startup #36157

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/src/main/asciidoc/vertx-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,32 @@ The browser must use the `vertx-eventbus` JavaScript library to consume the mess

</script>
</html>

----
=== Serve static resources not defined at startup
To serve static resources, add a specific Vert.x Web route to serve the files from given directory.
Use `@ConfigProperty` properties to make the paths configurable.
----
package org.acme.vertx;

import io.quarkus.runtime.StartupEvent;
import io.vertx.core.http.HttpMethod;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.StaticHandler;
import jakarta.enterprise.event.Observes;

public class MyStaticResources {

void installRoute(@Observes StartupEvent startupEvent, Router router) {
router.route()
.method(HttpMethod.GET).method(HttpMethod.HEAD)
.path("/static/*") // <1>
.handler(StaticHandler.create("static/")); // <2>
}
}
----
<1> Serve resources from the `static/` directory on the `static/` path. Example `static/image.png` will be served on `http://<host>:<port>/static/image.png`
<2> Static handler that serve files from an absolute path, but that's not recommended as it could cause security issues.

[#native-transport]
== Use native transports
Expand Down
Loading