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
24 lines
912 B
TypeScript
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;
|
|
},
|
|
}),
|
|
);
|