import { Server, Origins } from "boardgame.io/server"; import { AcrossTheHex } from "./src/game.js"; import { fileURLToPath } from "url"; import dotenv from "dotenv"; import * as fs from "fs/promises"; import type * as _ from "@fastify/middie"; export async function startServer() { const server = Server({ games: [AcrossTheHex], origins: [Origins.LOCALHOST], }); const env = dotenv.parse(await fs.readFile(new URL(".env", import.meta.url)).catch(() => "")); server.run({ port: +(env["SOCKETIO_PORT"] ?? 3100), lobbyConfig: { apiPort: +(env["LOBBY_PORT"] ?? 3200), } }); } export async function registerFastify(app: import("fastify").FastifyInstance, prefix: string) { const { default: fastifyStatic } = await import("@fastify/static"); app.register(fastifyStatic, { root: fileURLToPath(new URL(`./dist/client`, import.meta.url)), prefix: prefix, decorateReply: false, }); // @ts-ignore const handler = (await import(`./dist/server/entry.mjs`)).handler; app.use(handler); startServer(); }