import { FreshContext } from '$fresh/server.ts' import { useCsp } from ':src/csp/middleware.ts' import { useSecurityHeaders } from ':src/security_headers/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) // Allow service worker to serve root scope if (ctx.url.pathname.endsWith('island-startserviceworker.js')) { response.headers.set('Service-Worker-Allowed', '/') } return response }