From 60153a3b016bdd01ea7a4678dd4cd942309771c2 Mon Sep 17 00:00:00 2001 From: duckRabbitPy <78092825+duckRabbitPy@users.noreply.github.com> Date: Sun, 5 May 2024 12:11:51 +0100 Subject: [PATCH] set cache setHeaders --- server/src/httpServer/createHttpServer.ts | 22 ++++++++++++++-------- server/src/test/api.test.ts | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/server/src/httpServer/createHttpServer.ts b/server/src/httpServer/createHttpServer.ts index fd2f5d9..307f35d 100644 --- a/server/src/httpServer/createHttpServer.ts +++ b/server/src/httpServer/createHttpServer.ts @@ -5,6 +5,7 @@ import { gameRouter } from "./routes/game-sessions/game-sessions"; import { registerRouter } from "./routes/register/register"; import { authRouter } from "./routes/auth/auth"; import path from "path"; +import { Response } from "express"; import { wsApplication } from "@wll8/express-ws/dist/src/type"; import { pingRouter } from "./routes/db-ping/ping"; @@ -34,26 +35,31 @@ export function createHttpServer(app: wsApplication) { app.use("/", express.static(clientDistPath, { maxAge: MAX_CACHE_AGE })); // Serve static files from the dist/client folder in production + + const setHeaders = (res: Response) => { + res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); + }; + + // no-cache, no-store, must-revalidate" if (!isDev) { app.use( "/public", express.static(path.join(rootPath, "dist/public"), { - maxAge: MAX_CACHE_AGE, + setHeaders, }) ); - app.use( - "/", - express.static(path.join(rootPath, "dist/client"), { - maxAge: MAX_CACHE_AGE, - }) - ); + app.use("/", express.static(path.join(rootPath, "dist/client"), {})); } // Handle any other client routes by serving the React app's entry point app.get("*", (_, res) => { res.sendFile(path.join(clientDistPath, "index.html"), { - maxAge: MAX_CACHE_AGE, + headers: { + "Cache-Control": "no-store, no-cache, must-revalidate", + Pragma: "no-cache", + Expires: "0", + }, }); }); diff --git a/server/src/test/api.test.ts b/server/src/test/api.test.ts index 958f082..67969eb 100644 --- a/server/src/test/api.test.ts +++ b/server/src/test/api.test.ts @@ -170,7 +170,7 @@ const createRoomAuthProtectedTest = (pool: Pool) => { authorization: `Bearer a9jd-invalid-token-38af`, }, body: JSON.stringify({ - room: 123, + room: TEST_ROOM, }), } );