Replies: 1 comment
|
Yes— For Hono 4, start Bun from your project root and use: // src/app.ts
import { Hono } from "hono"
import { serveStatic } from "hono/bun"
const app = new Hono()
// Keep your existing middleware and app.route(...) registrations here,
// before the static fallback.
app.get("/api/health", (c) => c.json({ ok: true }))
app.get("*", serveStatic({ root: "./public" }))
export default appKeep your existing bun run src/server.tsWith that root, the URL-to-file mapping is:
The URL does not include Registering the static handler after your application routes lets those routes handle matching requests first. A missing static file falls through to your normal not-found handling; merely having Version note: the current Bun guide uses Everything under this static root is publicly servable; keep files requiring authorization outside it or protect all requests handled by the static middleware. I checked the documentation and source, but have not run your application. |
Uh oh!
There was an error while loading. Please reload this page.
I’m working on a Hono project using Bun, and my current file structure is:
Since I moved the public folder outside src, I want to ensure my Hono app (running with Bun) can still serve static files from it properly.
My Questions:
How can I configure Hono with Bun to serve static files from public while keeping my routes functional?
Do I need to adjust the serveStatic middleware in Hono or change how Bun handles file serving?
What’s the recommended way to handle this in a Bun + Hono setup?
All reactions