feat: connect vercel edge middleware to astro#7523
feat: connect vercel edge middleware to astro#7523ematipico merged 6 commits intofeat/vercel-edge-middlewarefrom
Conversation
🦋 Changeset detectedLatest commit: 06a5c8a The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| * prototype is the root `Object.prototype`. This includes objects created | ||
| * using object literals, but not for instance for class instances. | ||
| */ | ||
| function isPlainObject(value: unknown): value is object { |
There was a problem hiding this comment.
We have packages/internal-helpers now. I could see some of the things like this going there. Not blocking though, just an idea.
There was a problem hiding this comment.
I thought about it, and wasn't sure what to do. I will move the function there!
That's because after the SSR build step, So somewhere is accidentally importing esbuild in the compiled runtime code maybe. I'm not really sure and it's hard to debug these stuff. |
|
!preview vercel-edge-middleware |
|
|
I tested the feature and the middleware works! I could see my logs, and I could see the locals working and rendered in the Astro page, I could see the new Here's the plan: I will merge this PR once the CI passes. Then I will create a final PR that will merge all the new code to |
| analytics?: boolean; | ||
| imageService?: boolean; | ||
| imagesConfig?: VercelImageConfig; | ||
| createLocals?: CreateLocals; |
There was a problem hiding this comment.
Do we want to remove this option since we're using the file now?
Changes
This PR connects the Vercel Edge Middleware to the Astro middleware:
trySerializeLocalsto serialise thelocals. This is important because theselocalswill travel via headers, and we need to keep them when they are transferred from the vercel middleware to the Astro middleware;created a new API inside theAs per @bluwy suggestion, the new API is actually a new key file called@astrojs/verceladapter, this API is calledcreateLocalsand allows users to initialize theirlocalswith anything they want. The function accepts an object that containsrequestandcontext. You can check Vercel documentation;vercel-edge-middleware, it receives an object withrequestandcontextandesbuildwill bundle the file.localstoapp.render. Theselocalsare extracted from the headers of the request;Testing
I plan to create a preview release, create a new project and deploy it on Vercel.
Also, I added a snapshot test for the generated middleware. The reason is that it's very difficult to see how's the code generated, especially for reviewers. Please let me know how do feel about it; I am happy to remove it.
Docs
N/A Later when I know the APIs are stable and settled among the team members.