Skip to content

Commit

Permalink
Merge pull request #85 from duckRabbitPy/effect-3.0
Browse files Browse the repository at this point in the history
set cache setHeaders
  • Loading branch information
duckRabbitPy authored May 5, 2024
2 parents 1da0940 + 60153a3 commit c52c3ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions server/src/httpServer/createHttpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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",
},
});
});

Expand Down
2 changes: 1 addition & 1 deletion server/src/test/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const createRoomAuthProtectedTest = (pool: Pool) => {
authorization: `Bearer a9jd-invalid-token-38af`,
},
body: JSON.stringify({
room: 123,
room: TEST_ROOM,
}),
}
);
Expand Down

0 comments on commit c52c3ee

Please sign in to comment.