-
Notifications
You must be signed in to change notification settings - Fork 3k
Describe how you can serve static files with a Vert.x route #34278
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,12 +24,14 @@ Servlet filter, otherwise it will run directly on top of Vert.x with no Servlet | |
|
|
||
| == Serving Static Resources | ||
|
|
||
| To serve static resources you must place them in the `META-INF/resources` directory of your application. This location | ||
| === From the application jar | ||
|
|
||
| To serve static resources from the application jar, you must place them in the `META-INF/resources` directory of your application. This location | ||
| was chosen as it is the standard location for resources in `jar` files as defined by the Servlet spec. Even though | ||
| Quarkus can be used without Servlet, following this convention allows existing code that places its resources in this | ||
| location to function correctly. | ||
|
|
||
| === WebJar Locator Support | ||
| === From WebJars | ||
|
|
||
| If you are using webjars, like the following JQuery one: | ||
|
|
||
|
|
@@ -68,6 +70,33 @@ To use it, add the following to your project's dependencies: | |
| implementation("io.quarkus:quarkus-webjars-locator") | ||
| ---- | ||
|
|
||
| === From a local directory | ||
|
|
||
| Static resources can be served from a local directory by installing an additional route in the Vert.x router. | ||
|
|
||
| For instance, to serve resources from the `static/` directory relative to the current path at http://localhost:8080/static/, | ||
| you can install the following route: | ||
|
|
||
| [source,java] | ||
| ---- | ||
| package org.acme; | ||
|
|
||
| import io.quarkus.runtime.StartupEvent; | ||
| import io.vertx.ext.web.Router; | ||
| import io.vertx.ext.web.handler.StaticHandler; | ||
| import jakarta.enterprise.event.Observes; | ||
|
|
||
|
|
||
| public class StaticResources { | ||
|
|
||
| void installRoute(@Observes StartupEvent startupEvent, Router router) { | ||
| router.route() | ||
| .path("/static/*") | ||
| .handler(StaticHandler.create("static/")); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should have a list of static resources uses could mount if they choose to. |
||
| } | ||
| ---- | ||
|
|
||
| === HTTP Compression | ||
|
|
||
| The response body of a static resource is not compressed by default. | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to set an
order()here @cescoffier?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depends if you route conflicts with other routes. Here because it used /static, I don't believe there will be any conflict.