Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: vercel edge middleware support #7532

Merged
merged 23 commits into from
Jul 5, 2023
Merged

Conversation

ematipico
Copy link
Member

@ematipico ematipico commented Jun 30, 2023

Changes

This PR adds support for vercel edge middleware via Astro middleware.

This is an opt-in feature, and the @astrojs/vercel/serverless adapter will automatically create the edge middleware function for you.

Please refer to the readme for limitations and constraints.

To quickly opt in to the feature, you need to use the new option build.excludeMiddleware and - obviously - have a middleware file in your code base:

// astro.config.mjs
import {defineConfig} from "astro/config";
import vercel from "@astrojs/vercel";
export default definConfig({
   output: "server",
   adapter: vercel(),
   build: {
       excludeMiddleware: true
   }
})

This PR should be ready to be merged to main. I will create another preview release to test it a little bit, although I tested it locally, and the feature works as intended. There might be some edge cases that I didn't take into consideration.

Testing

Test cases were added along the way.

Docs

@withastro/maintainers-docs It's now time for your help to review the changes :) There are a bunch of changesets because a few stuff were added.

@changeset-bot
Copy link

changeset-bot bot commented Jun 30, 2023

🦋 Changeset detected

Latest commit: 8d7b6fc

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

@github-actions github-actions bot added pkg: integration Related to any renderer integration (scope) pkg: astro Related to the core `astro` package (scope) semver: minor Change triggers a `minor` release labels Jun 30, 2023
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

@ematipico ematipico marked this pull request as ready for review June 30, 2023 12:37
@ematipico ematipico requested a review from a team as a code owner June 30, 2023 12:37
@ematipico
Copy link
Member Author

!preview vercel-edge-middleware

@github-actions
Copy link
Contributor

 > [email protected] release /home/runner/work/astro/astro > pnpm run build && changeset publish "--tag" "next--vercel-edge-middleware" > [email protected] build /home/runner/work/astro/astro > turbo run build --filter=astro --filter=create-astro --filter="@astrojs/*" --filter="@benchmark/*" �[2m• Packages in scope: @astrojs/alpinejs, @astrojs/cloudflare, @astrojs/deno, @astrojs/image, @astrojs/internal-helpers, @astrojs/lit, @astrojs/markdoc, @astrojs/markdown-component, @astrojs/markdown-remark, @astrojs/mdx, @astrojs/netlify, @astrojs/node, @astrojs/partytown, @astrojs/preact, @astrojs/prefetch, @astrojs/prism, @astrojs/react, @astrojs/rss, @astrojs/sitemap, @astrojs/solid-js, @astrojs/svelte, @astrojs/tailwind, @astrojs/telemetry, @astrojs/turbolinks, @astrojs/underscore-redirects, @astrojs/vercel, @astrojs/vue, @astrojs/webapi, @benchmark/timer, astro, create-astro�[0m �[2m• Running�[0m �[2m�[1mbuild�[0m�[0m �[2min 31 packages�[0m �[2m• Remote caching enabled�[0m �[35m@astrojs/webapi:build: �[0mcache hit, suppressing logs �[2m5022b9b22168006a�[0m �[32m@astrojs/internal-helpers:build: �[0mcache hit, suppressing logs �[2m5a30529ab66446c3�[0m �[33m@astrojs/prism:build: �[0mcache hit, suppressing logs �[2m424b38cc1c7e8039�[0m �[35mcreate-astro:build: �[0mcache hit, suppressing logs �[2m85e7229e73b93747�[0m �[34m@astrojs/telemetry:build: �[0mcache hit, suppressing logs �[2m1bc6b4ad7d3d128f�[0m �[36m@astrojs/markdown-remark:build: �[0mcache hit, suppressing logs �[2m8340413bc418f7d3�[0m �[32mastro:build: �[0mcache miss, executing �[2m5476802615095523�[0m �[32mastro:build: �[0m �[32mastro:build: �[0m> [email protected] build /home/runner/work/astro/astro/packages/astro �[32mastro:build: �[0m> pnpm run prebuild && astro-scripts build "src/**/*.{ts,js}" && tsc && pnpm run postbuild �[32mastro:build: �[0m �[32mastro:build: �[0m �[32mastro:build: �[0m> [email protected] prebuild /home/runner/work/astro/astro/packages/astro �[32mastro:build: �[0m> astro-scripts prebuild --to-string "src/runtime/server/astro-island.ts" "src/runtime/client/{idle,load,media,only,visible}.ts" �[32mastro:build: �[0m �[32mastro:build: �[0m �[32mastro:build: �[0m> [email protected] postbuild /home/runner/work/astro/astro/packages/astro �[32mastro:build: �[0m> astro-scripts copy "src/**/*.astro" && astro-scripts copy "src/**/*.wasm" �[32mastro:build: �[0m �[36m@astrojs/alpinejs:build: �[0mcache miss, executing �[2md523338eb3aa1e16�[0m �[32m@astrojs/tailwind:build: �[0mcache miss, executing �[2mfeca3ae1e3cdabf9�[0m �[34m@benchmark/timer:build: �[0mcache miss, executing �[2m8a8d0f78ccb72b87�[0m �[35m@astrojs/mdx:build: �[0mcache miss, executing �[2m00a66e2db036ddf0�[0m �[35m@astrojs/prefetch:build: �[0mcache miss, executing �[2mf3a868648048e4e9�[0m �[33m@astrojs/deno:build: �[0mcache miss, executing �[2mdd26f2d71635c68e�[0m �[32m@astrojs/turbolinks:build: �[0mcache miss, executing �[2mbe901621b89558ac�[0m �[36m@astrojs/vue:build: �[0mcache miss, executing �[2m1632deac65fe2f0b�[0m �[33m@astrojs/rss:build: �[0mcache miss, executing �[2m961e28f059c12fab�[0m �[34m@astrojs/underscore-redirects:build: �[0mcache miss, executing �[2m5543f11dea8938b3�[0m �[36m@astrojs/alpinejs:build: �[0m �[36m@astrojs/alpinejs:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/alpinejs �[36m@astrojs/alpinejs:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[36m@astrojs/alpinejs:build: �[0m �[32m@astrojs/tailwind:build: �[0m �[32m@astrojs/tailwind:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/tailwind �[32m@astrojs/tailwind:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[32m@astrojs/tailwind:build: �[0m �[34m@benchmark/timer:build: �[0m �[34m@benchmark/timer:build: �[0m> @benchmark/[email protected] build /home/runner/work/astro/astro/benchmark/packages/timer �[34m@benchmark/timer:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[34m@benchmark/timer:build: �[0m �[35m@astrojs/mdx:build: �[0m �[35m@astrojs/mdx:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/mdx �[35m@astrojs/mdx:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[35m@astrojs/mdx:build: �[0m �[35m@astrojs/prefetch:build: �[0m �[35m@astrojs/prefetch:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/prefetch �[35m@astrojs/prefetch:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[35m@astrojs/prefetch:build: �[0m �[33m@astrojs/deno:build: �[0m �[33m@astrojs/deno:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/deno �[33m@astrojs/deno:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[33m@astrojs/deno:build: �[0m �[32m@astrojs/turbolinks:build: �[0m �[32m@astrojs/turbolinks:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/turbolinks �[32m@astrojs/turbolinks:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[32m@astrojs/turbolinks:build: �[0m �[33m@astrojs/rss:build: �[0m �[33m@astrojs/rss:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/astro-rss �[33m@astrojs/rss:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[33m@astrojs/rss:build: �[0m �[34m@astrojs/underscore-redirects:build: �[0m �[34m@astrojs/underscore-redirects:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/underscore-redirects �[34m@astrojs/underscore-redirects:build: �[0m> astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json �[34m@astrojs/underscore-redirects:build: �[0m �[36m@astrojs/vue:build: �[0m �[36m@astrojs/vue:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/vue �[36m@astrojs/vue:build: �[0m> astro-scripts build "src/index.ts" && astro-scripts build "src/editor.cts" --force-cjs --no-clean-dist && tsc �[36m@astrojs/vue:build: �[0m �[33m@astrojs/vercel:build: �[0mcache miss, executing �[2m11a60a45bd45ef38�[0m �[34m@astrojs/markdoc:build: �[0mcache miss, executing �[2m3296f3100c725f78�[0m �[36m@astrojs/solid-js:build: �[0mcache miss, executing �[2mfc5dcff6f288f98b�[0m �[35m@astrojs/image:build: �[0mcache miss, executing �[2m8a9de1b2f5625124�[0m �[32m@astrojs/react:build: �[0mcache miss, executing �[2m7e974069af2915f2�[0m �[33m@astrojs/svelte:build: �[0mcache miss, executing �[2mbef9fe3054638bdb�[0m �[34m@astrojs/partytown:build: �[0mcache miss, executing �[2md0bcc3c99296b995�[0m �[33m@astrojs/vercel:build: �[0m �[33m@astrojs/vercel:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/vercel �[33m@astrojs/vercel:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[33m@astrojs/vercel:build: �[0m �[35m@astrojs/image:build: �[0m �[35m@astrojs/image:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/image �[35m@astrojs/image:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[35m@astrojs/image:build: �[0m �[36m@astrojs/solid-js:build: �[0m �[36m@astrojs/solid-js:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/solid �[36m@astrojs/solid-js:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[36m@astrojs/solid-js:build: �[0m �[34m@astrojs/markdoc:build: �[0m �[34m@astrojs/markdoc:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/markdoc �[34m@astrojs/markdoc:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[34m@astrojs/markdoc:build: �[0m �[36m@astrojs/lit:build: �[0mcache miss, executing �[2m566b622226bcf1da�[0m �[35m@astrojs/node:build: �[0mcache miss, executing �[2m1bcab376f95616d7�[0m �[33m@astrojs/svelte:build: �[0m �[33m@astrojs/svelte:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/svelte �[33m@astrojs/svelte:build: �[0m> astro-scripts build "src/index.ts" && astro-scripts build "src/editor.cts" --force-cjs --no-clean-dist && tsc �[33m@astrojs/svelte:build: �[0m �[32m@astrojs/react:build: �[0m �[32m@astrojs/react:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/react �[32m@astrojs/react:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[32m@astrojs/react:build: �[0m �[34m@astrojs/partytown:build: �[0m �[34m@astrojs/partytown:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/partytown �[34m@astrojs/partytown:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[34m@astrojs/partytown:build: �[0m �[32m@astrojs/preact:build: �[0mcache miss, executing �[2md56440589af9ac99�[0m �[36m@astrojs/lit:build: �[0m �[36m@astrojs/lit:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/lit �[36m@astrojs/lit:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[36m@astrojs/lit:build: �[0m �[35m@astrojs/node:build: �[0m �[35m@astrojs/node:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/node �[35m@astrojs/node:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[35m@astrojs/node:build: �[0m �[32m@astrojs/preact:build: �[0m �[32m@astrojs/preact:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/preact �[32m@astrojs/preact:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[32m@astrojs/preact:build: �[0m �[33m@astrojs/cloudflare:build: �[0mcache miss, executing �[2m3be3f43f79dec72c�[0m �[34m@astrojs/netlify:build: �[0mcache miss, executing �[2m841603dcad388de9�[0m �[33m@astrojs/cloudflare:build: �[0m �[33m@astrojs/cloudflare:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/cloudflare �[33m@astrojs/cloudflare:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[33m@astrojs/cloudflare:build: �[0m �[34m@astrojs/netlify:build: �[0m �[34m@astrojs/netlify:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/netlify �[34m@astrojs/netlify:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[34m@astrojs/netlify:build: �[0m �[36m@astrojs/sitemap:build: �[0mcache miss, executing �[2ma6b08605077c322b�[0m �[36m@astrojs/sitemap:build: �[0m �[36m@astrojs/sitemap:build: �[0m> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/sitemap �[36m@astrojs/sitemap:build: �[0m> astro-scripts build "src/**/*.ts" && tsc �[36m@astrojs/sitemap:build: �[0m Tasks: 30 successful, 30 total Cached: 6 cached, 30 total Time: 1m11.236s 🦋 �[33mwarn�[39m �[31m===============================IMPORTANT!===============================�[39m 🦋 �[33mwarn�[39m Packages will be released under the next--vercel-edge-middleware tag 🦋 �[33mwarn�[39m �[31m----------------------------------------------------------------------�[39m 🦋 �[36minfo�[39m npm info astro 🦋 �[36minfo�[39m npm info @astrojs/prism 🦋 �[36minfo�[39m npm info @astrojs/rss 🦋 �[36minfo�[39m npm info create-astro 🦋 �[36minfo�[39m npm info @astrojs/alpinejs 🦋 �[36minfo�[39m npm info @astrojs/cloudflare 🦋 �[36minfo�[39m npm info @astrojs/deno 🦋 �[36minfo�[39m npm info @astrojs/image 🦋 �[36minfo�[39m npm info @astrojs/lit 🦋 �[36minfo�[39m npm info @astrojs/markdoc 🦋 �[36minfo�[39m npm info @astrojs/mdx 🦋 �[36minfo�[39m npm info @astrojs/netlify 🦋 �[36minfo�[39m npm info @astrojs/node 🦋 �[36minfo�[39m npm info @astrojs/partytown 🦋 �[36minfo�[39m npm info @astrojs/preact 🦋 �[36minfo�[39m npm info @astrojs/prefetch 🦋 �[36minfo�[39m npm info @astrojs/react 🦋 �[36minfo�[39m npm info @astrojs/sitemap 🦋 �[36minfo�[39m npm info @astrojs/solid-js 🦋 �[36minfo�[39m npm info @astrojs/svelte 🦋 �[36minfo�[39m npm info @astrojs/tailwind 🦋 �[36minfo�[39m npm info @astrojs/turbolinks 🦋 �[36minfo�[39m npm info @astrojs/vercel 🦋 �[36minfo�[39m npm info @astrojs/vue 🦋 �[36minfo�[39m npm info @astrojs/internal-helpers 🦋 �[36minfo�[39m npm info @astrojs/markdown-component 🦋 �[36minfo�[39m npm info @astrojs/markdown-remark 🦋 �[36minfo�[39m npm info @astrojs/telemetry 🦋 �[36minfo�[39m npm info @astrojs/underscore-redirects 🦋 �[36minfo�[39m npm info @astrojs/webapi 🦋 �[36minfo�[39m astro is being published because our local version (0.0.0-vercel-edge-middleware-20230630125718) has not been published on npm 🦋 �[33mwarn�[39m @astrojs/prism is not being published because version 2.1.2 is already published on npm 🦋 �[33mwarn�[39m @astrojs/rss is not being published because version 2.4.3 is already published on npm 🦋 �[33mwarn�[39m create-astro is not being published because version 3.1.8 is already published on npm 🦋 �[33mwarn�[39m @astrojs/alpinejs is not being published because version 0.2.2 is already published on npm 🦋 �[36minfo�[39m @astrojs/cloudflare is being published because our local version (0.0.0-vercel-edge-middleware-20230630125718) has not been published on npm 🦋 �[33mwarn�[39m @astrojs/deno is not being published because version 4.2.0 is already published on npm 🦋 �[33mwarn�[39m @astrojs/image is not being published because version 0.17.1 is already published on npm 🦋 �[33mwarn�[39m @astrojs/lit is not being published because version 2.1.0 is already published on npm 🦋 �[33mwarn�[39m @astrojs/markdoc is not being published because version 0.4.0 is already published on npm 🦋 �[33mwarn�[39m @astrojs/mdx is not being published because version 0.19.7 is already published on npm 🦋 �[33mwarn�[39m @astrojs/netlify is not being published because version 2.3.0 is already published on npm 🦋 �[33mwarn�[39m @astrojs/node is not being published because version 5.3.0 is already published on npm 🦋 �[33mwarn�[39m @astrojs/partytown is not being published because version 1.2.3 is already published on npm 🦋 �[33mwarn�[39m @astrojs/preact is not being published because version 2.2.1 is already published on npm 🦋 �[33mwarn�[39m @astrojs/prefetch is not being published because version 0.2.3 is already published on npm 🦋 �[33mwarn�[39m @astrojs/react is not being published because version 2.2.1 is already published on npm 🦋 �[33mwarn�[39m @astrojs/sitemap is not being published because version 1.3.3 is already published on npm 🦋 �[33mwarn�[39m @astrojs/solid-js is not being published because version 2.2.0 is already published on npm 🦋 �[33mwarn�[39m @astrojs/svelte is not being published because version 3.1.0 is already published on npm 🦋 �[33mwarn�[39m @astrojs/tailwind is not being published because version 4.0.0 is already published on npm 🦋 �[33mwarn�[39m @astrojs/turbolinks is not being published because version 0.2.2 is already published on npm 🦋 �[36minfo�[39m @astrojs/vercel is being published because our local version (0.0.0-vercel-edge-middleware-20230630125718) has not been published on npm 🦋 �[33mwarn�[39m @astrojs/vue is not being published because version 2.2.1 is already published on npm 🦋 �[33mwarn�[39m @astrojs/internal-helpers is not being published because version 0.1.1 is already published on npm 🦋 �[33mwarn�[39m @astrojs/markdown-component is not being published because version 1.0.5 is already published on npm 🦋 �[33mwarn�[39m @astrojs/markdown-remark is not being published because version 2.2.1 is already published on npm 🦋 �[33mwarn�[39m @astrojs/telemetry is not being published because version 2.1.1 is already published on npm 🦋 �[33mwarn�[39m @astrojs/underscore-redirects is not being published because version 0.1.0 is already published on npm 🦋 �[33mwarn�[39m @astrojs/webapi is not being published because version 2.2.0 is already published on npm 🦋 �[36minfo�[39m Publishing �[36m"astro"�[39m at �[32m"0.0.0-vercel-edge-middleware-20230630125718"�[39m 🦋 �[36minfo�[39m Publishing �[36m"@astrojs/cloudflare"�[39m at �[32m"0.0.0-vercel-edge-middleware-20230630125718"�[39m 🦋 �[36minfo�[39m Publishing �[36m"@astrojs/vercel"�[39m at �[32m"0.0.0-vercel-edge-middleware-20230630125718"�[39m 🦋 �[32msuccess�[39m packages published successfully: 🦋 [email protected] 🦋 @astrojs/[email protected] 🦋 @astrojs/[email protected] 🦋 Creating git tags... 🦋 New tag: [email protected] 🦋 New tag: @astrojs/[email protected] 🦋 New tag: @astrojs/[email protected]

.changeset/brown-shrimps-hug.md Outdated Show resolved Hide resolved
.changeset/long-geckos-battle.md Outdated Show resolved Hide resolved
packages/astro/src/@types/astro.ts Outdated Show resolved Hide resolved
packages/integrations/vercel/src/lib/nft.ts Show resolved Hide resolved
packages/integrations/vercel/README.md Show resolved Hide resolved
packages/integrations/vercel/README.md Outdated Show resolved Hide resolved
packages/integrations/vercel/README.md Outdated Show resolved Hide resolved
Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good @ematipico ! Left some copy edits to consider! 🙌

packages/astro/src/@types/astro.ts Outdated Show resolved Hide resolved
packages/astro/src/@types/astro.ts Outdated Show resolved Hide resolved
packages/integrations/vercel/README.md Outdated Show resolved Hide resolved
packages/integrations/vercel/README.md Outdated Show resolved Hide resolved
packages/integrations/vercel/README.md Outdated Show resolved Hide resolved
export default function({ request, context }) {
// do something with request and context
return {
title: "Spider-man's blog"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't believe you made me spell check this! 😂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what you get from me when I have to write content that is not "foo", "bar" or "lorem" 🤣

packages/integrations/vercel/README.md Outdated Show resolved Hide resolved
packages/integrations/vercel/README.md Outdated Show resolved Hide resolved
@ematipico ematipico merged commit 9e5fafa into main Jul 5, 2023
@ematipico ematipico deleted the feat/vercel-edge-middleware branch July 5, 2023 15:46
@astrobot-houston astrobot-houston mentioned this pull request Jul 5, 2023
matthewp pushed a commit that referenced this pull request Jul 11, 2023
Co-authored-by: Bjorn Lu <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope) semver: minor Change triggers a `minor` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants