You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.0 KiB

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)));
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,
});
// @ts-ignore
const handler = (await import(`./dist/server/entry.mjs`)).handler;
app.use(handler);
startServer();
}