mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 23:31:55 +00:00
247c78151c
## Description: Changes URL embeds within other platforms, e.g. Discord, WhatsApp & X. Updates game URLs to `/game/<code>` instead of `/#join=<code>` (required for embedded URLs). An added benefit of this is that you would be able to change a url from `openfront.io/game/RQDUy8nP?replay` to `api.openfront.io/game/RQDUy8nP?replay` (add api. In front) and be in the right place for the API data. Updates URLs when joining/leaving private lobbies Appends a random string to the end of the URL when inside a private lobby and options change - this is to force discord to update the embedded details. Updates URL in different game states to ?lobby / ?live and ?replay. These do nothing other than being used as a _cache-busting_ solution. ----------------------------------------------- ### **Lobby Info** Discord: <img width="556" height="487" alt="image" src="https://github.com/user-attachments/assets/efd4a06d-506c-4036-9403-ee7c9a669e21" /> WhatsApp: <img width="353" height="339" alt="image" src="https://github.com/user-attachments/assets/3b2d0c69-988c-424f-9dee-f4e6a6868f6b" /> x.com: <img width="588" height="325" alt="image" src="https://github.com/user-attachments/assets/d9e78169-20be-4a3e-8df4-8ad41d08a750" /> ------------------------- ### **Game Win Details** Discord: <img width="506" height="468" alt="image" src="https://github.com/user-attachments/assets/69947774-c943-4a50-b470-5634ed3bf3d7" /> WhatsApp: <img width="770" height="132" alt="image" src="https://github.com/user-attachments/assets/eec28bf8-bf64-4ab8-954e-03dfdd1aae40" /> x.com <img width="584" height="350" alt="image" src="https://github.com/user-attachments/assets/168063e2-b707-422b-b7a1-0025f3ebeb92" /> ## 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: w.o.n
32 lines
931 B
TypeScript
32 lines
931 B
TypeScript
import ejs from "ejs";
|
|
import type { Response } from "express";
|
|
import fs from "fs/promises";
|
|
|
|
export async function renderHtmlContent(htmlPath: string): Promise<string> {
|
|
const htmlContent = await fs.readFile(htmlPath, "utf-8");
|
|
return ejs.render(htmlContent, {
|
|
gitCommit: JSON.stringify(process.env.GIT_COMMIT ?? "undefined"),
|
|
instanceId: JSON.stringify(process.env.INSTANCE_ID ?? "undefined"),
|
|
});
|
|
}
|
|
|
|
export function setHtmlNoCacheHeaders(res: Response): void {
|
|
res.setHeader(
|
|
"Cache-Control",
|
|
"no-store, no-cache, must-revalidate, proxy-revalidate",
|
|
);
|
|
res.setHeader("Pragma", "no-cache");
|
|
res.setHeader("Expires", "0");
|
|
res.setHeader("ETag", "");
|
|
res.setHeader("Content-Type", "text/html");
|
|
}
|
|
|
|
export async function renderHtml(
|
|
res: Response,
|
|
htmlPath: string,
|
|
): Promise<void> {
|
|
const rendered = await renderHtmlContent(htmlPath);
|
|
setHtmlNoCacheHeaders(res);
|
|
res.send(rendered);
|
|
}
|