honojs / hono

Web framework built on Web Standards
https://hono.dev
MIT License
20.53k stars 595 forks source link

root option for serveStatic on Windows #3693

Open oscarotero opened 6 days ago

oscarotero commented 6 days ago

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: https://github.com/lumeland/cms/issues/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: https://github.com/honojs/hono/pull/3420) Previously, the relative path was passed but this stopped working after upgrading Hono so I had to change it (commit here: https://github.com/lumeland/cms/compare/v0.6.4...v0.6.5)