Inject server env vars into index.html, including instance id (#2888)

## Description:

Should fix the broken 1v1 on staging. The issue was that we had multiple
staging environments, and the matchmaker would often route a player to a
game on a different staging server, so the client couldn't find the
game.

So now each deployment has a unique id, and the matchmaker only connects
players & servers that have the same instance id.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

## Please put your Discord username so you can be contacted if a bug or
regression is found:

evan
This commit is contained in:
Evan
2026-01-13 13:03:58 -08:00
committed by GitHub
parent 85def73bd9
commit a77c6c3d9d
10 changed files with 97 additions and 70 deletions
+5 -23
View File
@@ -524,22 +524,12 @@ export class JoinPrivateLobbyModal extends BaseModal {
private async checkArchivedGame(
lobbyId: string,
): Promise<"success" | "not_found" | "version_mismatch" | "error"> {
const archivePromise = fetch(`${getApiBase()}/game/${lobbyId}`, {
const archiveResponse = await fetch(`${getApiBase()}/game/${lobbyId}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
const gitCommitPromise = fetch(`/commit.txt`, {
method: "GET",
headers: { "Content-Type": "application/json" },
cache: "no-cache",
});
const [archiveResponse, gitCommitResponse] = await Promise.all([
archivePromise,
gitCommitPromise,
]);
if (archiveResponse.status === 404) {
return "not_found";
@@ -554,19 +544,11 @@ export class JoinPrivateLobbyModal extends BaseModal {
return "version_mismatch";
}
let myGitCommit = "";
if (gitCommitResponse.status === 404) {
// commit.txt is not found when running locally
myGitCommit = "DEV";
} else if (gitCommitResponse.status === 200) {
myGitCommit = (await gitCommitResponse.text()).trim();
} else {
console.error("Error getting git commit:", gitCommitResponse.status);
return "error";
}
// Allow DEV to join games created with a different version for debugging.
if (myGitCommit !== "DEV" && parsed.data.gitCommit !== myGitCommit) {
if (
window.GIT_COMMIT !== "DEV" &&
parsed.data.gitCommit !== window.GIT_COMMIT
) {
const safeLobbyId = this.sanitizeForLog(lobbyId);
console.warn(
`Git commit hash mismatch for game ${safeLobbyId}`,
+2
View File
@@ -160,6 +160,8 @@ function updateAccountNavButton(userMeResponse: UserMeResponse | false) {
declare global {
interface Window {
GIT_COMMIT: string;
INSTANCE_ID: string;
turnstile: any;
enableAds: boolean;
PageOS: {
+3 -1
View File
@@ -120,7 +120,9 @@ export class MatchmakingModal extends BaseModal {
private async connect() {
const config = await getServerConfigFromClient();
this.socket = new WebSocket(`${config.jwtIssuer()}/matchmaking/join`);
this.socket = new WebSocket(
`${config.jwtIssuer()}/matchmaking/join?instance_id=${window.INSTANCE_ID}`,
);
this.socket.onopen = async () => {
console.log("Connected to matchmaking server");
setTimeout(() => {