Skip to content

Conversation

@mathias82
Copy link

Summary

This PR introduces support for serving static files from a local directory,
configurable via quarkus.http.local-static-resources.*.

New configuration

quarkus.http.local-static-resources.enabled=true
quarkus.http.local-static-resources.path=/local-static/
quarkus.http.local-static-resources.directory=local-static

Tests

Added LocalStaticResourcesTest which verifies:

  • Serving an existing file
  • Returning 404 when missing

@mathias82 mathias82 changed the title Add support for serving static resources from a local directory in Vert.x HTTP #39968 Add a configuration to serve a local directory with a static handler #39968 Nov 23, 2025
@mathias82 mathias82 changed the title Add a configuration to serve a local directory with a static handler #39968 Add a configuration to serve a local directory with a static handler Fix #39968 Nov 23, 2025
@mathias82 mathias82 force-pushed the feature-static-local-dir branch 4 times, most recently from dd79a29 to 2bc57dc Compare November 24, 2025 12:08
Copy link
Contributor

@ia3andy ia3andy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just cleaning non changed files

@ia3andy
Copy link
Contributor

ia3andy commented Nov 24, 2025

I also forgot, you need to add those files as watched for livereload

@mathias82 mathias82 force-pushed the feature-static-local-dir branch from 9744cb6 to 691e79a Compare November 24, 2025 14:05
@mathias82
Copy link
Author

I also forgot, you need to add those files as watched for livereload

ii have added @ia3andy

@mathias82 mathias82 force-pushed the feature-static-local-dir branch from 691e79a to 4a1de61 Compare November 24, 2025 14:16
@mathias82 mathias82 requested a review from ia3andy November 24, 2025 14:18
@mathias82 mathias82 requested a review from ia3andy November 24, 2025 18:15
@mathias82 mathias82 changed the title Add a configuration to serve a local directory with a static handler Fix #39968 Add a configuration to serve a local directory with a static handler Nov 24, 2025
@mathias82 mathias82 force-pushed the feature-static-local-dir branch from c6feebb to 55a80ff Compare November 25, 2025 07:50
@mathias82
Copy link
Author

Improve validation and handling of local static resources directory

  • Introduce normalizedDirectory() with safety checks
  • I used validated directory in both build steps
  • Remove unnecessary endpoint trailing-slash logic
  • Simplify dev-mode directory guard

@mathias82 mathias82 requested a review from ia3andy November 25, 2025 09:08
Copy link
Contributor

@ia3andy ia3andy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ia3andy
Copy link
Contributor

ia3andy commented Nov 25, 2025

@mathias82 the code is LGTM, could you add the doc part also, I remember an old doc doing this with the StaticHandler (which was bad), but maybe it was removed.

@quarkus-bot

This comment has been minimized.

@mathias82 mathias82 force-pushed the feature-static-local-dir branch from cdd5850 to 76d924b Compare November 25, 2025 10:37
@quarkus-bot

This comment has been minimized.

@quarkus-bot

This comment has been minimized.

@quarkus-bot

This comment has been minimized.

@mathias82 mathias82 force-pushed the feature-static-local-dir branch from 9cd78b0 to ec6685a Compare November 27, 2025 09:39
@quarkus-bot

This comment has been minimized.

@quarkus-bot

This comment has been minimized.

@mathias82 mathias82 force-pushed the feature-static-local-dir branch from ec6685a to 9fce3d1 Compare November 27, 2025 13:37
@@ -0,0 +1,3 @@
quarkus.http.local-static-resources.enabled=true
Copy link
Contributor

@ia3andy ia3andy Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more I look at it the more I think using local and resources are confusing, with META-INF/resources which are also local static resources.

path is the path on disk which also makes it clear that it is not the endpoint.

Using / as default is also better as most of the time those static directory are serving at root.

I would suggest using this as default:

quarkus.http.static-dir.enabled=false
quarkus.http.static-dir.endpoint=/
quarkus.http.static-dir.path=static

Copy link
Member

@sberyozkin sberyozkin Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ia3andy If I understand the @FroMage's comment correctly, quarkus.http.static-dir.endpoint=/ should enable it, without having to also type quarkus.http.static-dir.enabled=true.

Having a default static (static-resources ?) value for quarkus.http.static-dir.path is good.
Perhaps quarkus.http.static-resources-dir or quarkus.http.static-resources-directory is clearer, even if more verbose ? Though I'll let you and @mathias82 agree on this one, thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok that's good too, just don't add resources or local in the naming as explained that makes it confusing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks both. I'll avoid using local or resources in the naming to prevent confusion with META-INF/resources, and I'll stick with the clearer static directory naming as suggested.
I have updated the configuration keys accordingly and push the changes.

@quarkus-bot

This comment has been minimized.

@quarkus-bot

This comment has been minimized.

@mathias82 mathias82 requested a review from ia3andy November 27, 2025 18:39
@quarkus-bot

This comment has been minimized.

@quarkus-bot

This comment has been minimized.

Comment on lines 17 to 28
/**
* The URL path under which the local directory is exposed,
* e.g. {@code /local-static}.
*/
@WithDefault("/local-static")
String endpoint();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* The URL path under which the local directory is exposed,
* e.g. {@code /local-static}.
*/
@WithDefault("/local-static")
String endpoint();
/**
* The base endpoint under which the local directory is exposed,
* <p>
* e.g. {@code /static} with hello.txt will be serve at <code>/static/hello.txt</code>.
*/
@WithDefault("/static")
String endpoint();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 71 to 82
To expose the contents of a `static/` directory under the `/local-static` path:

[source,properties]
----
quarkus.http.static-dir.path=/local-static
quarkus.http.static-dir.directory=static
----

With this configuration, a file located at `static/index.html` will be available at:
`http://localhost:8080/local-static/index.html`.

To disable serving local static resources explicitly:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To expose the contents of a `static/` directory under the `/local-static` path:
[source,properties]
----
quarkus.http.static-dir.path=/local-static
quarkus.http.static-dir.directory=static
----
With this configuration, a file located at `static/index.html` will be available at:
`http://localhost:8080/local-static/index.html`.
To disable serving local static resources explicitly:
To expose the contents of a `static/` directory under the `/static` endpoint:
[source,properties]
----
quarkus.http.static-dir.endpoint=/static
quarkus.http.static-dir.path=static
----
With this configuration, a file located at `static/index.html` will be available at:
`http://localhost:8080/static/index.html`.
To disable serving local static resources explicitly:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mathias82 any reason not to auto enable when endpoint or path is not empty as @FroMage suggested?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ia3andy @FroMage There is one reason: this feature exposes a local filesystem directory over HTTP.

If we auto-enable it as soon as endpoint or path is set, it becomes easier
for large apps with layered configuration to accidentally expose a directory
just because some partial config was inherited or left behind.

By keeping enabled as an explicit opt-in switch, we avoid accidental exposure
and make the intent very clear: nothing is served unless the user consciously
enables it.

That said, if the project convention is to auto-enable on config, I can update
the implementation accordingly, I just wanted to highlight the security/ops
angle behind the current design.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FroMage I let you decide on that one :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mathias82 the change I suggested is still appllicable

@mathias82 mathias82 requested a review from ia3andy November 28, 2025 10:43

Router router = httpRouter.getValue();
router.route(basePath + "/*")
.handler(new HttpStaticDirHandler(staticFiles));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mathias82 what is this?

Copy link
Author

@mathias82 mathias82 Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ia3andy This registers a catch-all Vert.x route for the configured static directory.

registerHttpStaticDirRoute collects all discovered static files at build time and
passes them to registerHttpStaticDir(...), which at runtime installs:

router.route(basePath + "/*").handler(new HttpStaticDirHandler(staticFiles));

So this line effectively exposes every file under the configured static-dir.path
at <basePath>/*, and delegates the resolution to HttpStaticDirHandler.

@quarkus-bot

This comment has been minimized.

@mathias82 mathias82 requested a review from ia3andy November 28, 2025 13:01
@mathias82 mathias82 force-pushed the feature-static-local-dir branch from 672e2a8 to 1dc209d Compare November 28, 2025 15:03
@quarkus-bot
Copy link

quarkus-bot bot commented Nov 28, 2025

Status for workflow Quarkus Documentation CI

This is the status report for running Quarkus Documentation CI on commit 1dc209d.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

Warning

There are other workflow runs running, you probably need to wait for their status before merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a configuration to serve a local directory with a static handler

5 participants