init: me-web 个人简历前端
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import type { Hono } from "hono";
|
||||
import type { HttpBindings } from "@hono/node-server";
|
||||
import { serveStatic } from "@hono/node-server/serve-static";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
type App = Hono<{ Bindings: HttpBindings }>;
|
||||
|
||||
export function serveStaticFiles(app: App) {
|
||||
const distPath = path.resolve(import.meta.dirname, "../dist/public");
|
||||
|
||||
app.use("*", serveStatic({ root: distPath }));
|
||||
|
||||
app.notFound((c) => {
|
||||
const accept = c.req.header("accept") ?? "";
|
||||
if (!accept.includes("text/html")) {
|
||||
return c.json({ error: "Not Found" }, 404);
|
||||
}
|
||||
const indexPath = path.resolve(distPath, "index.html");
|
||||
const content = fs.readFileSync(indexPath, "utf-8");
|
||||
return c.html(content);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user