blob: 60a94085521b12d42572b22f9a4b477cd06d7f31 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
import { When, whenAmI } from '@it-astro:when';
import type { MiddlewareHandler } from 'astro';
const middlewares: Record<When, MiddlewareHandler> = {
[When.Client]: () => {
throw new Error('Client should not run a middleware!');
},
[When.DevServer]: (_, next) => next(),
[When.Server]: (_, next) => next(),
[When.Prerender]: (ctx, next) => {
if (ctx.locals.runtime === undefined) {
ctx.locals.runtime = {
env: process.env,
};
}
return next();
},
[When.StaticBuild]: (_, next) => next(),
};
export const onRequest = middlewares[whenAmI];
|