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

fix: use vercel routing utils #525

Merged
merged 8 commits into from
Jan 30, 2025
Merged

fix: use vercel routing utils #525

merged 8 commits into from
Jan 30, 2025

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Jan 29, 2025

Changes

This updates the Vercel adapter to use the @vercel/routing-utils to generate redirect routes, rather than building them ourselves. Instead we generate the redirects in the hgher-level path-to-regexp syntax, which we then pass to getTransformedRoutes. This has the benefit of automatically handling trailing slash redirects and various Vercel edge cases.

We also now validate and normalise the generated routes using normalizeRoutes.

This also adds an error message for conflicting config if the user has conflicting trailingSlash set in the Vercel config. There is no reason to use it in the vercel.json now, because the adapter does the same thing.

Fixes #418
Fix #499

Testing

Docs

Copy link

changeset-bot bot commented Jan 29, 2025

🦋 Changeset detected

Latest commit: 2852086

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 20 packages
Name Type
@astrojs/vercel Patch
@test/astro-vercel-basic Patch
@test/astro-vercel-image Patch
@test/astro-vercel-integration-assets Patch
@test/vercel-isr Patch
@test/vercel-max-duration Patch
@test/vercel-edge-middleware-with-edge-file Patch
@test/vercel-edge-middleware-without-edge-file Patch
@test/astro-vercel-no-output Patch
@test/astro-vercel-prerendered-error-pages Patch
@test/astro-vercel-redirects-serverless Patch
@test/astro-vercel-redirects Patch
@test/vercel-server-islands Patch
@test/astro-vercel-serverless-prerender Patch
@test/astro-vercel-serverless-with-dynamic-routes Patch
@test/astro-vercel-static-assets Patch
@test/astro-vercel-static Patch
@test/vercel-streaming Patch
@test/astro-vercel-with-web-analytics-enabled-output-as-static Patch
vercel-hosted-astro-project Patch

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 the pkg: vercel Related to Vercel adapter (scope) label Jan 29, 2025
@ascorbic
Copy link
Contributor Author

!preview vercel-routing

Copy link
Contributor

Snapshots have been released for the following packages:

  • @astrojs/vercel@experimental--vercel-routing
Publish Log
🦋  warn ===============================IMPORTANT!===============================
🦋  warn Packages will be released under the experimental--vercel-routing tag
🦋  warn ----------------------------------------------------------------------
🦋  info npm info @astrojs/cloudflare
🦋  info npm info @astrojs/netlify
🦋  info npm info @astrojs/node
🦋  info npm info @astrojs/vercel
🦋  warn @astrojs/cloudflare is not being published because version 12.2.1 is already published on npm
🦋  warn @astrojs/netlify is not being published because version 6.1.0 is already published on npm
🦋  warn @astrojs/node is not being published because version 9.0.2 is already published on npm
🦋  info @astrojs/vercel is being published because our local version (0.0.0-vercel-routing-20250129140158) has not been published on npm
🦋  info Publishing "@astrojs/vercel" at "0.0.0-vercel-routing-20250129140158"
🦋  success packages published successfully:
🦋  @astrojs/vercel@0.0.0-vercel-routing-20250129140158
🦋  Creating git tag...
🦋  New tag:  @astrojs/vercel@0.0.0-vercel-routing-20250129140158
Build Log

> root@0.0.0 build /home/runner/work/adapters/adapters
> turbo run build --filter="@astrojs/*"

• Packages in scope: @astrojs/cloudflare, @astrojs/netlify, @astrojs/node, @astrojs/test-utils, @astrojs/vercel
• Running build in 5 packages
• Remote caching disabled
::group::@astrojs/vercel:build
cache miss, executing 66bbce296455d7a3

> @astrojs/vercel@0.0.0-vercel-routing-20250129140158 build /home/runner/work/adapters/adapters/packages/vercel
> tsc

::endgroup::
::group::@astrojs/netlify:build
cache miss, executing 875e44a528ced37a

> @astrojs/netlify@6.1.0 build /home/runner/work/adapters/adapters/packages/netlify
> tsc

::endgroup::
::group::@astrojs/node:build
cache miss, executing 9a9ffb470d95e6c2

> @astrojs/node@9.0.2 build /home/runner/work/adapters/adapters/packages/node
> tsc

::endgroup::
::group::@astrojs/cloudflare:build
cache miss, executing 4354f5d9d0d2701c

> @astrojs/cloudflare@12.2.1 build /home/runner/work/adapters/adapters/packages/cloudflare
> tsc

::endgroup::

 Tasks:    4 successful, 4 total
Cached:    0 cached, 4 total
  Time:    6.239s 

assert.notEqual(blogRoute, undefined);
assert.equal(blogRoute.headers.Location.startsWith('/team/articles'), true);
assert.equal(blogRoute.status, 301);
});

it('define trailingSlash redirect for sub pages', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed because this isn't how they're done now: it's a global thing instead

@ascorbic ascorbic marked this pull request as ready for review January 29, 2025 14:26
@ascorbic
Copy link
Contributor Author

!preview vercel-routing

Copy link
Contributor

Snapshots have been released for the following packages:

  • @astrojs/vercel@experimental--vercel-routing
Publish Log
🦋  warn ===============================IMPORTANT!===============================
🦋  warn Packages will be released under the experimental--vercel-routing tag
🦋  warn ----------------------------------------------------------------------
🦋  info npm info @astrojs/cloudflare
🦋  info npm info @astrojs/netlify
🦋  info npm info @astrojs/node
🦋  info npm info @astrojs/vercel
🦋  warn @astrojs/cloudflare is not being published because version 12.2.1 is already published on npm
🦋  warn @astrojs/netlify is not being published because version 6.1.0 is already published on npm
🦋  warn @astrojs/node is not being published because version 9.0.2 is already published on npm
🦋  info @astrojs/vercel is being published because our local version (0.0.0-vercel-routing-20250129162731) has not been published on npm
🦋  info Publishing "@astrojs/vercel" at "0.0.0-vercel-routing-20250129162731"
🦋  success packages published successfully:
🦋  @astrojs/vercel@0.0.0-vercel-routing-20250129162731
🦋  Creating git tag...
🦋  New tag:  @astrojs/vercel@0.0.0-vercel-routing-20250129162731
Build Log

> root@0.0.0 build /home/runner/work/adapters/adapters
> turbo run build --filter="@astrojs/*"

• Packages in scope: @astrojs/cloudflare, @astrojs/netlify, @astrojs/node, @astrojs/test-utils, @astrojs/vercel
• Running build in 5 packages
• Remote caching disabled
::group::@astrojs/vercel:build
cache miss, executing e81fad366180c6d8

> @astrojs/vercel@0.0.0-vercel-routing-20250129162731 build /home/runner/work/adapters/adapters/packages/vercel
> tsc

::endgroup::
::group::@astrojs/netlify:build
cache miss, executing 875e44a528ced37a

> @astrojs/netlify@6.1.0 build /home/runner/work/adapters/adapters/packages/netlify
> tsc

::endgroup::
::group::@astrojs/node:build
cache miss, executing 9a9ffb470d95e6c2

> @astrojs/node@9.0.2 build /home/runner/work/adapters/adapters/packages/node
> tsc

::endgroup::
::group::@astrojs/cloudflare:build
cache miss, executing 4354f5d9d0d2701c

> @astrojs/cloudflare@12.2.1 build /home/runner/work/adapters/adapters/packages/cloudflare
> tsc

::endgroup::

 Tasks:    4 successful, 4 total
Cached:    0 cached, 4 total
  Time:    6.211s 

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

It looks good code-wise, however it would be great to address some unclear points of the code with some comment

packages/vercel/src/index.ts Show resolved Hide resolved
packages/vercel/src/index.ts Outdated Show resolved Hide resolved
packages/vercel/src/index.ts Outdated Show resolved Hide resolved
@ascorbic ascorbic requested a review from ematipico January 30, 2025 10:55
@ascorbic ascorbic merged commit 6ef9a6f into main Jan 30, 2025
8 checks passed
@github-actions github-actions bot mentioned this pull request Jan 23, 2025
@blaine-arcjet
Copy link

Just tried upgrading to this version and now I'm getting a crash with the error: Error: Cannot find module '@vercel-internals/path-to-regexp'

@blaine-arcjet
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: vercel Related to Vercel adapter (scope)
Projects
None yet
3 participants