-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update adapters to better support astro v5 (#454)
Co-authored-by: Florian Lefebvre <[email protected]>
- Loading branch information
1 parent
d7e7d5e
commit 83cedad
Showing
10 changed files
with
609 additions
and
468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
'@astrojs/cloudflare': patch | ||
'@astrojs/test-utils': patch | ||
'@astrojs/netlify': patch | ||
'@astrojs/vercel': patch | ||
'@astrojs/node': patch | ||
--- | ||
|
||
Improves Astro 5 support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,12 @@ | ||
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) => { | ||
export const onRequest: MiddlewareHandler = (context, next) => { | ||
if (context.isPrerendered) { | ||
// @ts-expect-error | ||
if (ctx.locals.runtime === undefined) { | ||
// @ts-expect-error | ||
ctx.locals.runtime = { | ||
env: process.env, | ||
}; | ||
} | ||
return next(); | ||
}, | ||
[When.StaticBuild]: (_, next) => next(), | ||
}; | ||
context.locals.runtime ??= { | ||
env: process.env, | ||
}; | ||
} | ||
|
||
export const onRequest = middlewares[whenAmI]; | ||
return next(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.