40d3a66055
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
32 lines
917 B
TypeScript
32 lines
917 B
TypeScript
import { Hono } from "hono";
|
|
import { bodyLimit } from "hono/body-limit";
|
|
import type { HttpBindings } from "@hono/node-server";
|
|
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
|
import { appRouter } from "./router";
|
|
import { createContext } from "./context";
|
|
import { env } from "./lib/env";
|
|
|
|
const app = new Hono<{ Bindings: HttpBindings }>();
|
|
|
|
app.use(bodyLimit({ maxSize: 50 * 1024 * 1024 }));
|
|
app.use("/api/trpc/*", async (c) => {
|
|
return fetchRequestHandler({
|
|
endpoint: "/api/trpc",
|
|
req: c.req.raw,
|
|
router: appRouter,
|
|
createContext,
|
|
});
|
|
});
|
|
app.all("/api/*", (c) => c.json({ error: "Not Found" }, 404));
|
|
|
|
export default app;
|
|
|
|
if (env.isProduction) {
|
|
const { serve } = await import("@hono/node-server");
|
|
|
|
const port = parseInt(process.env.PORT || "3000");
|
|
serve({ fetch: app.fetch, port }, () => {
|
|
console.log(`Server running on http://localhost:${port}/`);
|
|
});
|
|
}
|