Skip to content
Source
Sign inSign up
samwillis/one-million-boxes
Open History to see the last commit

index.ts

20 lines739 Bytes

1import { attachDatabasePool } from "@vercel/functions"
2import pg from "pg"
3import { createApp } from "../server/app.js"
4import { runtimeConfig } from "../server/config.js"
5import { GameStore } from "../server/store.js"
6​
7const config = runtimeConfig()
8// Reuse connections across Fluid compute requests. Neon's pooled endpoint
9// multiplexes them; Vercel releases idle sockets when an instance is suspended.
10const pool = new pg.Pool({
11 connectionString: config.databaseUrl,
12 max: 5,
13 idleTimeoutMillis: 5000,
14 connectionTimeoutMillis: 10000,
15})
16attachDatabasePool(pool)
17const app = createApp(config, new GameStore(pool))
18​
19// Native Web handler: all /api routes share this stateless Hono application.
20export default { fetch: app.fetch }