diff --git a/.env.sample b/.env.sample index 40d6c96..0edc9fb 100644 --- a/.env.sample +++ b/.env.sample @@ -4,3 +4,4 @@ PUBLIC_LOBBY_SERVER="http://localhost:3200/" SOCKETIO_PORT=3100 LOBBY_PORT=3200 +BASE="/" diff --git a/.gitignore b/.gitignore index 5e3299e..f55ddce 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ node_modules/ src/env.d.ts dist/ +*.js +.turbo/ diff --git a/astro.config.mjs b/astro.config.mjs index 741e84e..f1525a1 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -2,9 +2,13 @@ import { fileURLToPath } from "url"; import { defineConfig } from "astro/config"; import solidJs from "@astrojs/solid-js"; import node from "@astrojs/node"; +import dotenv from "dotenv"; + +dotenv.config(); export default defineConfig({ - site: import.meta.env.PUBLIC_BASE_URL ?? "http://localhost:3000/", + site: process.PUBLIC_BASE_URL ?? "http://localhost:3000/", + base: process.env.ASTRO_BASE, integrations: [solidJs()], outDir: fileURLToPath(new URL("./dist/", import.meta.url)), output: "server", diff --git a/build-index.sh b/build-index.sh new file mode 100755 index 0000000..8d42b02 --- /dev/null +++ b/build-index.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +yarn run esbuild ./index.ts \ + --bundle \ + --platform=node \ + --outfile=./index.js \ + --packages=external \ + --format=esm \ + --alias:boardgame.io/server=boardgame.io/dist/cjs/server.js \ + --alias:boardgame.io/core=boardgame.io/dist/cjs/core.js diff --git a/index.ts b/index.ts index 4d5a5d4..d9c4ecb 100644 --- a/index.ts +++ b/index.ts @@ -11,7 +11,7 @@ export async function startServer() { origins: [Origins.LOCALHOST], }); - const env = dotenv.parse(await fs.readFile(new URL(".env", import.meta.url))); + const env = dotenv.parse(await fs.readFile(new URL(".env", import.meta.url)).catch(() => "")); server.run({ port: +(env["SOCKETIO_PORT"] ?? 3100), lobbyConfig: { @@ -25,6 +25,7 @@ export async function registerFastify(app: import("fastify").FastifyInstance, pr app.register(fastifyStatic, { root: fileURLToPath(new URL(`./dist/client`, import.meta.url)), prefix: prefix, + decorateReply: false, }); // @ts-ignore diff --git a/package.json b/package.json index 781f109..fb5f477 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "dev": "astro dev", "server": "bun ./server.ts", "lint": "astro check && tsc --noEmit", - "build": "astro build" + "build": "astro build && ./build-index.sh" }, "dependencies": { "@astrojs/node": "^5.1.2", @@ -19,6 +19,7 @@ "astro": "^2.3.3", "boardgame.io": "^0.50.2", "dotenv": "^16.3.1", + "esbuild": "^0.18.14", "sass": "^1.62.1", "solid-js": "^1.7.8" }, diff --git a/src/components/Toolbar.tsx b/src/components/Toolbar.tsx index 3d7b8e7..fa0d96d 100644 --- a/src/components/Toolbar.tsx +++ b/src/components/Toolbar.tsx @@ -1,4 +1,4 @@ -import { PLAYER_COLORS } from "../consts.js"; +import { BASE_URL, PLAYER_COLORS } from "../consts.js"; import classes from "./Toolbar.module.css"; import PlayerTile from "../tile-player-any.svg?raw"; import { Building, Buildings, PlaceableBuildings } from "../game.js"; @@ -98,7 +98,7 @@ function ToolbarItem(props: { > { props.type !== "road" && - + } ; }