2025-10-10 23:04:50 -07:00
|
|
|
import { createRequestHandler } from "@react-router/express";
|
|
|
|
|
import { drizzle } from "drizzle-orm/postgres-js";
|
|
|
|
|
import express from "express";
|
|
|
|
|
import postgres from "postgres";
|
2025-10-11 20:56:00 -07:00
|
|
|
import { RouterContextProvider } from "react-router";
|
2025-10-10 23:04:50 -07:00
|
|
|
|
2025-10-16 18:15:04 -07:00
|
|
|
import { DatabaseContext } from "../database/context";
|
|
|
|
|
import * as schema from "../database/schema";
|
|
|
|
|
import { expressValueContext } from "../app/contexts/express";
|
2025-10-10 23:04:50 -07:00
|
|
|
|
|
|
|
|
export const app = express();
|
|
|
|
|
|
|
|
|
|
if (!process.env.DATABASE_URL) throw new Error("DATABASE_URL is required");
|
|
|
|
|
|
|
|
|
|
const client = postgres(process.env.DATABASE_URL);
|
|
|
|
|
const db = drizzle(client, { schema });
|
|
|
|
|
app.use((_, __, next) => DatabaseContext.run(db, next));
|
|
|
|
|
|
|
|
|
|
app.use(
|
|
|
|
|
createRequestHandler({
|
2025-10-16 18:15:04 -07:00
|
|
|
build: () => import("virtual:react-router/server-build") as any,
|
2025-10-10 23:04:50 -07:00
|
|
|
getLoadContext() {
|
2025-10-16 18:15:04 -07:00
|
|
|
const provider = new RouterContextProvider();
|
|
|
|
|
provider.set(expressValueContext, "Hello from Express");
|
|
|
|
|
return provider as any; // Type assertion needed - RouterContextProvider is the context
|
2025-10-10 23:04:50 -07:00
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
);
|