From 0f9951bb0e70f9e6e2c4fdfc2bc51b6f93cd429e Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Mon, 24 Oct 2022 16:50:22 +1100 Subject: TestClient middleware will now add cache misses to file for generate:client script to fetch. Also patch discord icon top left --- src/api/middlewares/TestClient.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/api/middlewares/TestClient.ts b/src/api/middlewares/TestClient.ts index 62128b36..ad759fdb 100644 --- a/src/api/middlewares/TestClient.ts +++ b/src/api/middlewares/TestClient.ts @@ -13,7 +13,7 @@ export default function TestClient(app: Application) { const agent = new ProxyAgent(); const assetCache = new Map< string, - { response: FetchResponse; buffer: Buffer } + { response: FetchResponse; buffer: Buffer; } >(); const indexHTML = fs.readFileSync( path.join(ASSET_FOLDER_PATH, "client_test", "index.html"), @@ -76,13 +76,7 @@ export default function TestClient(app: Application) { app.use("/assets", express.static(path.join(ASSET_FOLDER_PATH, "cache"))); app.get("/assets/:file", async (req: Request, res: Response) => { - if (!hasWarnedAboutCache) { - hasWarnedAboutCache = true; - if (req.params.file.includes(".js")) - console.warn( - `[TestClient] Cache miss for file ${req.params.file}! Use 'npm run generate:client' to cache and patch.`, - ); - } + if (req.params.file.includes(".map")) return res.status(404); delete req.headers.host; var response: FetchResponse; @@ -124,6 +118,16 @@ export default function TestClient(app: Application) { }); assetCache.set(req.params.file, { buffer, response }); + if (response.status == 200) { + // if (!hasWarnedAboutCache) { + hasWarnedAboutCache = true; + console.warn( + `[TestClient] Cache miss for file ${req.params.file}! Use 'npm run generate:client' to cache and patch.`, + ); + await fs.promises.appendFile(path.join(ASSET_FOLDER_PATH, "cacheMisses"), req.params.file + "\n"); + // } + } + return res.send(buffer); }); app.get("/developers*", (req: Request, res: Response) => { -- cgit 1.4.1