Skip to content

root option for serveStatic on Windows #3693

Description

@oscarotero

What version of Hono are you using?

4.6.11

What runtime/platform is your app running on? (with version if possible)

Deno

What steps can reproduce the bug?

I'm using this middleware in this project to serve static files from a directory specified with the root option: https://github.com/lumeland/cms/blob/main/adapters/lume.ts#L124-L129

The site.dest() returns the absolute path of the root folder. In Linux/Mac it has the format /foo/bar. In Windows is C:/foo/bar (note the /separator instead of \, since Windows supports both separators (I think it's not relevant here, but just in case).

This works fine in Linux and Mac but not in Windows (issue: lumeland/cms#34)

What is the expected behavior?

I expect the root variable interpreted as an absolute path to the base folder.
Inspecting the code here looks like it's not always treated as absolute path, only if the path starts with / (which is not compatible with Windows).

What do you see instead?

404 errors for all requests

Additional information

This is a breaking change introduced in Hono in the version 4.6.3 (this is the PR with more info: #3420)
Previously, the relative path was passed but this stopped working after upgrading Hono so I had to change it (commit here: lumeland/cms@v0.6.4...v0.6.5)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions