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";
|
2026-03-21 09:44:05 -07:00
|
|
|
import type { ServerBuild } from "react-router";
|
2025-10-11 20:56:00 -07:00
|
|
|
import { RouterContextProvider } from "react-router";
|
2025-10-10 23:04:50 -07:00
|
|
|
|
2025-10-24 21:20:19 -07:00
|
|
|
import { DatabaseContext } from "~/database/context";
|
|
|
|
|
import * as schema from "~/database/schema";
|
|
|
|
|
import { expressValueContext } from "~/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({
|
2026-03-21 09:44:05 -07:00
|
|
|
build: () => import("virtual:react-router/server-build") as unknown as Promise<ServerBuild>,
|
|
|
|
|
// @ts-ignore -- RouterContextProvider is the correct runtime type but tsconfig.server.json can't resolve the conditional type statically
|
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");
|
2026-03-21 09:44:05 -07:00
|
|
|
return provider as unknown as RouterContextProvider;
|
2025-10-10 23:04:50 -07:00
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
);
|