diff --git a/apps/backend/src/index.ts b/apps/backend/src/index.ts index 0e750f3..423abea 100644 --- a/apps/backend/src/index.ts +++ b/apps/backend/src/index.ts @@ -38,8 +38,28 @@ app.route("/api", expensesRouter); app.route("/api/telegram", telegramRouter); app.route("/api/wallets", walletsRouter); -app.use("/assets/*", serveStatic({ root: "./web" })); -app.get("*", serveStatic({ path: "./web/index.html" })); +// Los assets incluyen un hash en el nombre, así que se pueden cachear para +// siempre. El index.html no debe cachearse: referencia los assets con hash y, +// si queda cacheado, el navegador sigue sirviendo el bundle viejo después de +// un deploy (por eso una nueva versión no se ve hasta un hard refresh). +app.use( + "/assets/*", + serveStatic({ + root: "./web", + onFound: (_path, c) => { + c.header("Cache-Control", "public, max-age=31536000, immutable"); + }, + }), +); +app.get( + "*", + serveStatic({ + path: "./web/index.html", + onFound: (_path, c) => { + c.header("Cache-Control", "no-cache"); + }, + }), +); eventBus.on("quotes-updated", () => { cache.invalidateByPrefix("quotes:");