website/routes/_middleware.ts

23 lines
802 B
TypeScript
Raw Normal View History

import { FreshContext } from '$fresh/server.ts'
2024-07-09 11:00:35 +02:00
import { useCsp } from ':src/csp/middleware.ts'
import { useSecurityHeaders } from ':src/security_headers/middleware.ts'
import { useServiceworker } from ':src/serviceworker/middleware.ts'
import { useSession } from ':src/session/middleware.ts'
import { SessionStore } from ':src/session/mod.ts'
export async function handler(request: Request, ctx: FreshContext) {
// Update fresh context state with session
ctx.state = { ...ctx.state, session: SessionStore.getFromRequest(request) }
// Get response
const response = await ctx.next()
// Use custom middleware hooks
useSecurityHeaders(request, response, ctx)
2024-07-09 11:00:35 +02:00
await useCsp(request, response, ctx)
useSession(request, response, ctx)
useServiceworker(request, response, ctx)
2024-06-13 12:20:47 +02:00
return response
}