1import type { MiddlewareHandler } from "astro";
2
3/**
4 * Astro middleware: runs inside workerd for on-demand routes (dev + live).
5 * Exercises both middleware surfaces — writing `Astro.locals` (read by
6 * `/locals`) and mutating the outgoing response headers.
7 */
8export const onRequest: MiddlewareHandler = async (context, next) => {
9 context.locals.fromMiddleware = "set-by-middleware";
10 const response = await next();
11 response.headers.set("x-middleware", "hit");
12 return response;
13};