feat(server): middleware params (#1314)

This commit is contained in:
Reed von Redwitz
2023-07-10 15:06:43 +02:00
committed by GitHub
parent 27622a190e
commit 724c81f2c7
9 changed files with 142 additions and 39 deletions
+17
View File
@@ -98,6 +98,23 @@ export const handler = [
];
```
It should be noted that `middleware` has access to route parameters. If you're
running a fictitious `routes/[tenant]/admin/_middleware.ts` like this:
```ts
import { MiddlewareHandlerContext } from "$fresh/server.ts";
export async function handler(_req: Request, ctx: MiddlewareHandlerContext) {
const currentTenant = ctx.params.tenant;
//do something with the tenant
const resp = await ctx.next();
return resp;
}
```
and the request is to `mysaas.com/acme/admin/`, then `currentTenant` will have
the value of `acme` in your middleware.
## Middleware Destination
To set the stage for this section, `MiddlewareHandlerContext` looks like this: