brackt/server/app.ts
Claude 79201820a9
Consolidate server postgres connections into one shared pool
Four separate postgres() clients were open simultaneously (app, timer,
snapshots, socket), each defaulting to 10 connections, exhausting the
database's max_connections limit. Replaced with a single shared lazy-
initialized client in server/db.ts using a Proxy to defer the
DATABASE_URL check until first use (preserving test compatibility).

Also bumps the CS2 Champions Stage stochastic test from 200 → 1000
iterations to eliminate flakiness.

https://claude.ai/code/session_019w21Nkf5TvTZHH6oVHaQXR
2026-04-05 19:52:46 +00:00

24 lines
912 B
TypeScript

import { createRequestHandler } from "@react-router/express";
import express from "express";
import type { ServerBuild } from "react-router";
import { RouterContextProvider } from "react-router";
import { DatabaseContext } from "~/database/context";
import { db } from "./db";
import { expressValueContext } from "~/contexts/express";
export const app = express();
app.use((_, __, next) => DatabaseContext.run(db, next));
app.use(
createRequestHandler({
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
getLoadContext() {
const provider = new RouterContextProvider();
provider.set(expressValueContext, "Hello from Express");
return provider as unknown as RouterContextProvider;
},
}),
);