`serveStatic` does not work when set absolute path to `root`
What version of Hono are you using?
4.4.12
What runtime/platform is your app running on?
Deno and Bun
What steps can reproduce the bug?
This is minimal script to reproduce the bug. This script can be executed with deno run --allow-net --allow-read command.
import { Hono } from "jsr:@hono/hono@^4.4.12";
import { serveStatic } from "jsr:@hono/hono@^4.4.12/deno";
const app = new Hono();
app.use(
"*",
serveStatic({
root: "/tmp/public_html"
})
);
Deno.serve(app.fetch);
The directory structure of /tmp/public_html/:
/tmp/public_html/
└── index.html
/tmp/public_html/index.html:
<p>test</p>
When accsessing http://localhost:8000, the server returns 404 Not Found and outputs an error:
NotFound: No such file or directory (os error 2): open './tmp/public_html/index.html'
NotFound: No such file or directory (os error 2): open './tmp/public_html/'
What is the expected behavior?
No response
What do you see instead?
No response
Additional information
No response
+1
Same here. Just tried on Bun. serveStatic doesn't serve file.
I am still not able to make it work. The referenced pull request talks about allowAbsoluteRoot which is nowhere to be found in the types. Guidance needed. Should this work or not?
I still have the same Problem. allowAbsoluteRoot does not work.
In the code it looks like it determines automatically if the path is absolute by checking if it starts with /.
That doesn't work for Windows paths!
Hi @thephluxer
Is that a Windows-specific problem? If so, it will be fixed in the future by #3477. I want you to try the branch version of hono to confirm it works correctly. Can you take a look at the comment and try it?
https://github.com/honojs/hono/pull/3477#issuecomment-3031263813