website/routes/_middleware.ts

23 lines
802 B
TypeScript

import { FreshContext } from '$fresh/server.ts'
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)
await useCsp(request, response, ctx)
useSession(request, response, ctx)
useServiceworker(request, response, ctx)
return response
}