Skip to content

Commit

Permalink
Added documentation on Serve static resources not defined at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
dvsingh9 committed Sep 26, 2023
1 parent e6ea6d5 commit b1f4879
Showing 1 changed file with 25 additions and 0 deletions.
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 @@ -917,7 +917,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

0 comments on commit b1f4879

Please sign in to comment.