H
Hono2d ago
leon

static files 404 when in subdirectory of assets

Hello, i am using hono with a cloudflare worker to serve the asset folder 'assets' as seen in the examples:
<p>
Try visiting: <a href="/my-file.txt">/my-file.txt</a> and <a href="/folder/nested-file.txt">/folder/nested-file.txt</a>
</p>
<p>
Try visiting: <a href="/my-file.txt">/my-file.txt</a> and <a href="/folder/nested-file.txt">/folder/nested-file.txt</a>
</p>
both files exist in the assets directory (it is the serve-static hono github example) however Hono loads the file my-file.txt from the assets root but /folder/nested-file.txtgives a file not found 404 all config is the standard given here: https://github.com/honojs/examples/tree/main/serve-static i have no idea why even the example is not working. any ideas to try would be great!
GitHub
examples/serve-static at main · honojs/examples
Examples using Hono. Contribute to honojs/examples development by creating an account on GitHub.
7 Replies
ambergristle
ambergristle2d ago
is /folder in the public dir? i'd also recommend reading these docs: https://hono.dev/docs/getting-started/cloudflare-workers#serve-static-files
leon
leonOP2d ago
as per the examples it is the "assets" folder, which is configured in the wragler.toml
No description
leon
leonOP2d ago
wrangler.toml
name = "hono-example-basic"
compatibility_date = "2024-09-19"

assets = { directory = "./assets/" }
name = "hono-example-basic"
compatibility_date = "2024-09-19"

assets = { directory = "./assets/" }
ambergristle
ambergristle2d ago
Idk that you need all the dots and slashes in the directory name And I don’t think you need to use serveStatic at all
leon
leonOP2d ago
i have not changed the example at all from the example in the github repo, so it is just odd that the example is not working i have fixed the issue. i was running node v18.14.1, but have now updated to lts v22.14.0. all static files are now served. perhaps a minimum node version check should be introduced into hono, i cannot see mention of it on the hono site (could have very well missed it)
ambergristle
ambergristle2d ago
cloudflare workers run on the workerd runtime, using wrangler locally no?
leon
leonOP2d ago
i have no idea, but i think whatever node version you use locally, is matched on wrangler deploy as i was having the same issues when the app was deployed

Did you find this page helpful?