Skip to content

Commit 5766d71

Browse files
committed
config
1 parent a7714cd commit 5766d71

33 files changed

+153
-154
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"${workspaceFolder}/src/server/Server.ts"
2323
],
2424
"env": {
25-
"GAME_ENV": "dev"
25+
"GAME_ENV": "Dev"
2626
},
2727
"console": "integratedTerminal",
2828
"internalConsoleOptions": "neverOpen",

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"html.validate.scripts": false
3+
}

index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656
/>
5757
<meta property="og:type" content="game" />
5858

59+
<!-- Server Configuration -->
60+
<script>
61+
window.SERVER_CONFIG = <%- serverConfig %>;
62+
</script>
63+
5964
<!-- CrazyGames SDK -->
6065
<script
6166
src="https://sdk.crazygames.com/crazygames-sdk-v3.js"

nginx.conf

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,25 +113,6 @@ server {
113113
proxy_set_header X-Forwarded-Proto $scheme;
114114
}
115115

116-
# /api/env endpoint - Cache for 1 hour
117-
location = /api/env {
118-
proxy_pass http://127.0.0.1:3000;
119-
proxy_http_version 1.1;
120-
121-
# Cache configuration
122-
proxy_cache API_CACHE;
123-
proxy_cache_valid 200 1h; # Cache successful responses for 1 hour
124-
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
125-
proxy_cache_lock on;
126-
add_header X-Cache-Status $upstream_cache_status;
127-
128-
# Standard proxy headers
129-
proxy_set_header Host $host;
130-
proxy_set_header X-Real-IP $remote_addr;
131-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
132-
proxy_set_header X-Forwarded-Proto $scheme;
133-
}
134-
135116
# /commit.txt endpoint - Cache for 5 seconds
136117
location = /commit.txt {
137118
proxy_pass http://127.0.0.1:3000;

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"build-prod": "concurrently --kill-others-on-fail \"tsc --noEmit\" \"vite build\"",
66
"start:client": "vite",
77
"start:server": "tsx src/server/Server.ts",
8-
"start:server-dev": "cross-env GAME_ENV=dev tsx src/server/Server.ts",
9-
"dev": "cross-env GAME_ENV=dev concurrently \"npm run start:client\" \"npm run start:server-dev\"",
10-
"dev:staging": "cross-env GAME_ENV=dev API_DOMAIN=api.openfront.dev concurrently \"npm run start:client\" \"npm run start:server-dev\"",
11-
"dev:prod": "cross-env GAME_ENV=dev API_DOMAIN=api.openfront.io concurrently \"npm run start:client\" \"npm run start:server-dev\"",
8+
"start:server-dev": "cross-env GAME_ENV=Dev tsx src/server/Server.ts",
9+
"dev": "cross-env GAME_ENV=Dev concurrently \"npm run start:client\" \"npm run start:server-dev\"",
10+
"dev:staging": "cross-env GAME_ENV=Dev API_DOMAIN=api.openfront.dev concurrently \"npm run start:client\" \"npm run start:server-dev\"",
11+
"dev:prod": "cross-env GAME_ENV=Dev API_DOMAIN=api.openfront.io concurrently \"npm run start:client\" \"npm run start:server-dev\"",
1212
"docs:map-generator": "cd map-generator && go doc -cmd -u -all",
1313
"tunnel": "npm run build-prod && npm run start:server",
1414
"test": "vitest run",

src/client/ClientGameRunner.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Env } from "src/core/configuration/Env";
12
import { translateText } from "../client/Utils";
23
import { EventBus } from "../core/EventBus";
34
import {
@@ -182,8 +183,9 @@ async function createClientGame(
182183
if (lobbyConfig.gameStartInfo === undefined) {
183184
throw new Error("missing gameStartInfo");
184185
}
185-
const config = await getConfig(
186+
const config = getConfig(
186187
lobbyConfig.gameStartInfo.config,
188+
Env.GAME_ENV,
187189
userSettings,
188190
lobbyConfig.gameRecord !== undefined,
189191
);
@@ -200,6 +202,7 @@ async function createClientGame(
200202
}
201203
const worker = new WorkerClient(
202204
lobbyConfig.gameStartInfo,
205+
Env.GAME_ENV,
203206
lobbyConfig.clientID,
204207
);
205208
await worker.initialize();

src/client/HostLobbyModal.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { TemplateResult, html } from "lit";
22
import { customElement, state } from "lit/decorators.js";
33
import { copyToClipboard, translateText } from "../client/Utils";
4-
import { getServerConfigFromClient } from "../core/configuration/ConfigLoader";
4+
import { getServerConfig } from "../core/configuration/ConfigLoader";
55
import {
66
Difficulty,
77
Duos,
@@ -1156,7 +1156,7 @@ export class HostLobbyModal extends BaseModal {
11561156
console.log(
11571157
`Starting private game with map: ${GameMapType[this.selectedMap as keyof typeof GameMapType]} ${this.useRandomMap ? " (Randomly selected)" : ""}`,
11581158
);
1159-
const config = await getServerConfigFromClient();
1159+
const config = getServerConfig();
11601160
const response = await fetch(
11611161
`${window.location.origin}/${config.workerPath(this.lobbyId)}/api/start_game/${this.lobbyId}`,
11621162
{
@@ -1178,7 +1178,7 @@ export class HostLobbyModal extends BaseModal {
11781178
}
11791179

11801180
private async pollPlayers() {
1181-
const config = await getServerConfigFromClient();
1181+
const config = getServerConfig();
11821182
fetch(`/${config.workerPath(this.lobbyId)}/api/game/${this.lobbyId}`, {
11831183
method: "GET",
11841184
headers: {
@@ -1231,7 +1231,7 @@ export class HostLobbyModal extends BaseModal {
12311231
}
12321232

12331233
async function createLobby(creatorClientID: string): Promise<GameInfo> {
1234-
const config = await getServerConfigFromClient();
1234+
const config = getServerConfig();
12351235
try {
12361236
const id = generateID();
12371237
const response = await fetch(

src/client/JoinPrivateLobbyModal.ts

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { html, TemplateResult } from "lit";
22
import { customElement, query, state } from "lit/decorators.js";
3+
import { Env } from "src/core/configuration/Env";
34
import { copyToClipboard, translateText } from "../client/Utils";
45
import {
56
ClientInfo,
@@ -8,7 +9,7 @@ import {
89
GameRecordSchema,
910
} from "../core/Schemas";
1011
import { generateID } from "../core/Util";
11-
import { getServerConfigFromClient } from "../core/configuration/ConfigLoader";
12+
import { getServerConfig } from "../core/configuration/ConfigLoader";
1213
import { GameMode } from "../core/game/Game";
1314
import { UserSettings } from "../core/game/UserSettings";
1415
import { getApiBase } from "./Api";
@@ -511,7 +512,7 @@ export class JoinPrivateLobbyModal extends BaseModal {
511512
}
512513

513514
private async checkActiveLobby(lobbyId: string): Promise<boolean> {
514-
const config = await getServerConfigFromClient();
515+
const config = getServerConfig();
515516
const url = `/${config.workerPath(lobbyId)}/api/game/${lobbyId}/exists`;
516517

517518
const response = await fetch(url, {
@@ -548,22 +549,12 @@ export class JoinPrivateLobbyModal extends BaseModal {
548549
private async checkArchivedGame(
549550
lobbyId: string,
550551
): Promise<"success" | "not_found" | "version_mismatch" | "error"> {
551-
const archivePromise = fetch(`${getApiBase()}/game/${lobbyId}`, {
552+
const archiveResponse = await fetch(`${getApiBase()}/game/${lobbyId}`, {
552553
method: "GET",
553554
headers: {
554555
"Content-Type": "application/json",
555556
},
556557
});
557-
const gitCommitPromise = fetch(`/commit.txt`, {
558-
method: "GET",
559-
headers: { "Content-Type": "application/json" },
560-
cache: "no-cache",
561-
});
562-
563-
const [archiveResponse, gitCommitResponse] = await Promise.all([
564-
archivePromise,
565-
gitCommitPromise,
566-
]);
567558

568559
if (archiveResponse.status === 404) {
569560
return "not_found";
@@ -578,16 +569,7 @@ export class JoinPrivateLobbyModal extends BaseModal {
578569
return "version_mismatch";
579570
}
580571

581-
let myGitCommit = "";
582-
if (gitCommitResponse.status === 404) {
583-
// commit.txt is not found when running locally
584-
myGitCommit = "DEV";
585-
} else if (gitCommitResponse.status === 200) {
586-
myGitCommit = (await gitCommitResponse.text()).trim();
587-
} else {
588-
console.error("Error getting git commit:", gitCommitResponse.status);
589-
return "error";
590-
}
572+
const myGitCommit = Env.GIT_COMMIT;
591573

592574
// Allow DEV to join games created with a different version for debugging.
593575
if (myGitCommit !== "DEV" && parsed.data.gitCommit !== myGitCommit) {
@@ -616,7 +598,7 @@ export class JoinPrivateLobbyModal extends BaseModal {
616598
private async pollPlayers() {
617599
const lobbyId = this.currentLobbyId;
618600
if (!lobbyId) return;
619-
const config = await getServerConfigFromClient();
601+
const config = getServerConfig();
620602

621603
fetch(`/${config.workerPath(lobbyId)}/api/game/${lobbyId}`, {
622604
method: "GET",

src/client/Main.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { UserMeResponse } from "../core/ApiSchemas";
33
import { EventBus } from "../core/EventBus";
44
import { GameRecord, GameStartInfo, ID } from "../core/Schemas";
55
import { GameEnv } from "../core/configuration/Config";
6-
import { getServerConfigFromClient } from "../core/configuration/ConfigLoader";
6+
import { getServerConfig } from "../core/configuration/ConfigLoader";
77
import { GameType } from "../core/game/Game";
88
import { UserSettings } from "../core/game/UserSettings";
99
import "./AccountModal";
@@ -735,7 +735,7 @@ class Client {
735735
this.gameStop();
736736
document.body.classList.remove("in-game");
737737
}
738-
const config = await getServerConfigFromClient();
738+
const config = getServerConfig();
739739

740740
const pattern = this.userSettings.getSelectedPatternName(
741741
await fetchCosmetics(),
@@ -895,7 +895,7 @@ class Client {
895895
private async getTurnstileToken(
896896
lobby: JoinLobbyEvent,
897897
): Promise<string | null> {
898-
const config = await getServerConfigFromClient();
898+
const config = getServerConfig();
899899
if (
900900
config.env() === GameEnv.Dev ||
901901
lobby.gameStartInfo?.config.gameType === GameType.Singleplayer
@@ -955,7 +955,7 @@ async function getTurnstileToken(): Promise<{
955955
throw new Error("Failed to load Turnstile script");
956956
}
957957

958-
const config = await getServerConfigFromClient();
958+
const config = getServerConfig();
959959
const widgetId = window.turnstile.render("#turnstile-container", {
960960
sitekey: config.turnstileSiteKey(),
961961
size: "normal",

src/client/Matchmaking.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { html, LitElement } from "lit";
22
import { customElement, query, state } from "lit/decorators.js";
33
import { UserMeResponse } from "../core/ApiSchemas";
4-
import { getServerConfigFromClient } from "../core/configuration/ConfigLoader";
4+
import { getServerConfig } from "../core/configuration/ConfigLoader";
55
import { generateID } from "../core/Util";
66
import { getUserMe } from "./Api";
77
import { getPlayToken } from "./Auth";
@@ -143,7 +143,7 @@ export class MatchmakingModal extends BaseModal {
143143
}
144144

145145
private async connect() {
146-
const config = await getServerConfigFromClient();
146+
const config = getServerConfig();
147147

148148
this.socket = new WebSocket(`${config.jwtIssuer()}/matchmaking/join`);
149149
this.socket.onopen = async () => {
@@ -222,7 +222,7 @@ export class MatchmakingModal extends BaseModal {
222222
if (this.gameID === null) {
223223
return;
224224
}
225-
const config = await getServerConfigFromClient();
225+
const config = getServerConfig();
226226
const url = `/${config.workerPath(this.gameID)}/api/game/${this.gameID}/exists`;
227227

228228
const response = await fetch(url, {

0 commit comments

Comments
 (0)