fix(server): no cache

This commit is contained in:
RainbowBird
2026-03-30 19:45:43 +08:00
parent 2caae8ee41
commit 33bf61f3f7
2 changed files with 19 additions and 0 deletions
+10
View File
@@ -74,6 +74,16 @@ async function buildApp(deps: AppDeps) {
const logger = useLogger('app').useGlobalConfig()
const app = new Hono<HonoEnv>()
.use('*', async (c, next) => {
await next()
// NOTICE: All API responses should be non-cacheable. Auth responses can
// carry session state through redirects, and stale API payloads are not
// safe to serve from edge caches after user/account mutations.
c.res.headers.set('Cache-Control', 'no-store, no-cache, private, max-age=0')
c.res.headers.set('Pragma', 'no-cache')
c.res.headers.set('Expires', '0')
})
.use(
'/api/*',
cors({
+9
View File
@@ -31,6 +31,15 @@ export function createAuth(db: Database, env: Env, metrics?: AuthMetrics | null)
enabled: true,
},
session: {
// NOTICE: keep a short-lived signed session cache cookie so follow-up
// session reads avoid hitting the database on every request.
cookieCache: {
enabled: true,
maxAge: 60 * 5,
},
},
baseURL: env.API_SERVER_URL,
trustedOrigins: request => getAuthTrustedOrigins(env, request),