summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--packages/transport-http/src/app.ts21
1 files changed, 20 insertions, 1 deletions
diff --git a/packages/transport-http/src/app.ts b/packages/transport-http/src/app.ts
index 9e4fc8a..a9dcbe5 100644
--- a/packages/transport-http/src/app.ts
+++ b/packages/transport-http/src/app.ts
@@ -678,12 +678,31 @@ export function createApp(opts: CreateServerOptions): Hono {
// ─── Static frontend serving (catch-all, API routes take precedence) ──────
if (opts.webDir !== undefined) {
const webDir = opts.webDir;
+ const MIME: Record<string, string> = {
+ ".js": "text/javascript; charset=utf-8",
+ ".mjs": "text/javascript; charset=utf-8",
+ ".css": "text/css; charset=utf-8",
+ ".html": "text/html; charset=utf-8",
+ ".json": "application/json; charset=utf-8",
+ ".svg": "image/svg+xml",
+ ".png": "image/png",
+ ".jpg": "image/jpeg",
+ ".ico": "image/x-icon",
+ ".woff": "font/woff",
+ ".woff2": "font/woff2",
+ ".txt": "text/plain; charset=utf-8",
+ ".wasm": "application/wasm",
+ };
app.get("*", async (c) => {
const urlPath = new URL(c.req.url).pathname;
const filePath = `${webDir}${urlPath}`;
const file = Bun.file(filePath);
if (await file.exists()) {
- return new Response(file);
+ const ext = filePath.slice(filePath.lastIndexOf("."));
+ const contentType = MIME[ext] ?? "application/octet-stream";
+ return new Response(file, {
+ headers: { "Content-Type": contentType },
+ });
}
// SPA fallback: serve index.html for client-side routing
const indexFile = Bun.file(`${webDir}/index.html`);