diff --git a/src/server/index.ts b/src/server/index.ts index 54789ea..e8382ea 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -1,5 +1,6 @@ import { Hono } from "hono"; import { serveStatic } from "hono/bun"; +import { db as prodDb } from "../db/index.ts"; import { seedDefaults } from "../db/seed.ts"; import { mcpRoutes } from "./mcp/index.ts"; import { requireAuth } from "./middleware/auth.ts"; @@ -22,7 +23,13 @@ app.get("/api/health", (c) => { return c.json({ status: "ok" }); }); -// Auth middleware for write operations (POST/PUT/DELETE) on non-auth routes +// Inject production database into request context +app.use("/api/*", async (c, next) => { + c.set("db", prodDb); + return next(); +}); + +// Auth middleware for write operations (POST/PUT/PATCH/DELETE) on non-auth routes app.use("/api/*", async (c, next) => { // Skip auth routes — they handle their own auth if (c.req.path.startsWith("/api/auth")) return next(); diff --git a/src/server/routes/settings.ts b/src/server/routes/settings.ts index 89a921c..422fd7b 100644 --- a/src/server/routes/settings.ts +++ b/src/server/routes/settings.ts @@ -1,6 +1,5 @@ import { eq } from "drizzle-orm"; import { Hono } from "hono"; -import { db as prodDb } from "../../db/index.ts"; import { settings } from "../../db/schema.ts"; type Env = { Variables: { db?: any } }; @@ -8,7 +7,7 @@ type Env = { Variables: { db?: any } }; const app = new Hono(); app.get("/:key", (c) => { - const database = c.get("db") ?? prodDb; + const database = c.get("db"); const key = c.req.param("key"); const row = database .select() @@ -20,7 +19,7 @@ app.get("/:key", (c) => { }); app.put("/:key", async (c) => { - const database = c.get("db") ?? prodDb; + const database = c.get("db"); const key = c.req.param("key"); const body = await c.req.json<{ value: string }>();