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

index.ts

21 lines744 Bytes

1import { serve } from "@hono/node-server"
2import pg from "pg"
3import { createApp } from "./app.js"
4import { runtimeConfig } from "./config.js"
5import { GameStore } from "./store.js"
6​
7const config = runtimeConfig()
8const pool = new pg.Pool({ connectionString: config.databaseUrl })
9const store = new GameStore(pool)
10// Run pnpm db:init before starting the API; startup never changes the schema.
11const app = createApp(config, store)
12​
13const server = serve({ fetch: app.fetch, hostname: "127.0.0.1", port: config.port })
14console.log(`Game API: http://127.0.0.1:${config.port}`)
15​
16for (const signal of ["SIGINT", "SIGTERM"] as const)
17 process.on(signal, () => {
18 server.close(() => {
19 void pool.end().then(() => process.exit(0))
20 })
21 })