-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: vercel edge middleware support (#7532)
Co-authored-by: Bjorn Lu <[email protected]> Co-authored-by: Sarah Rainsberger <[email protected]>
- Loading branch information
1 parent
cfd5b2b
commit 9e5fafa
Showing
36 changed files
with
758 additions
and
50 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,11 @@ | ||
--- | ||
'astro': minor | ||
--- | ||
|
||
The `astro/middleware` module exports a new utility called `trySerializeLocals`. | ||
|
||
This utility can be used by adapters to validate their `locals` before sending it | ||
to the Astro middleware. | ||
|
||
This function will throw a runtime error if the value passed is not serializable, so | ||
consumers will need to handle that error. |
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,24 @@ | ||
--- | ||
'astro': minor | ||
--- | ||
|
||
Astro exposes the middleware file path to the integrations in the hook `astro:build:ssr` | ||
|
||
```ts | ||
// myIntegration.js | ||
import type { AstroIntegration } from 'astro'; | ||
function integration(): AstroIntegration { | ||
return { | ||
name: "fancy-astro-integration", | ||
hooks: { | ||
'astro:build:ssr': ({ middlewareEntryPoint }) => { | ||
if (middlewareEntryPoint) { | ||
// do some operations | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
The `middlewareEntryPoint` is only defined if the user has created an Astro middleware. |
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,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Correctly track the middleware during the SSR build. |
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,11 @@ | ||
--- | ||
'@astrojs/vercel': minor | ||
--- | ||
|
||
Support for Vercel Edge Middleware via Astro middleware. | ||
|
||
When a project uses the new option Astro `build.excludeMiddleware`, the | ||
`@astrojs/vercel/serverless` adapter will automatically create a Vercel Edge Middleware | ||
that will automatically communicate with the Astro Middleware. | ||
|
||
Check the [documentation](https://github.com/withastro/astro/blob/main/packages/integrations/vercel/README.md##vercel-edge-middleware-with-astro-middleware) for more details. |
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,7 @@ | ||
--- | ||
'astro': minor | ||
--- | ||
|
||
The `astro/middleware` module exports a new API called `createContext`. | ||
|
||
This a low-level API that adapters can use to create a context that can be consumed by middleware functions. |
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,20 @@ | ||
--- | ||
'astro': minor | ||
--- | ||
|
||
Introduced a new build option for SSR, called `build.excludeMiddleware`. | ||
|
||
```js | ||
// astro.config.mjs | ||
import {defineConfig} from "astro/config"; | ||
|
||
export default defineConfig({ | ||
build: { | ||
excludeMiddleware: true | ||
} | ||
}) | ||
``` | ||
|
||
When enabled, the code that belongs to be middleware **won't** be imported | ||
by the final pages/entry points. The user is responsible for importing it and | ||
calling it manually. |
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
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
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
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.