* The chart endpoints live in src/api.ts and return data, not responses, so this * file stays the single place that decides headers on an authenticated reply. * Everything under `/api/` is behind the same session check as the pages.
(env: Env, url: URL)
| 206 | * Everything under `/api/` is behind the same session check as the pages. |
| 207 | */ |
| 208 | async function apiResponse(env: Env, url: URL): Promise<Response> { |
| 209 | const result = await handleApi(env, url); |
| 210 | return json(result.body, { |
| 211 | status: result.status, |
| 212 | // Chart data is daily-granular, so a few minutes in the browser's private |
| 213 | // cache saves D1 a round of identical queries on every panel re-render. |
| 214 | // Anything without an explicit lifetime keeps the no-store default. |
| 215 | headers: result.cacheControl ? { 'cache-control': result.cacheControl } : undefined, |
| 216 | }); |
| 217 | } |
| 218 | |
| 219 | /** Gated static assets: the dashboard shell, its JS, its CSS, the chart library. */ |
| 220 | async function serveAsset(env: Env, request: Request): Promise<Response> { |