Skip to content

Commit

Permalink
handle edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Nov 6, 2024
1 parent c6fa87a commit ad68def
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,17 @@ function static_vercel_config(builder, config, dir) {
/** @type {import('./index.js').ImagesConfig | undefined} */
const images = config.images;

for (const [src, redirect] of builder.prerendered.redirects) {
for (let [src, redirect] of builder.prerendered.redirects) {
if (src.replace(/\/$/, '') !== redirect.location.replace(/\/$/, '')) {
// handle the extreme edge case of a `/foo` -> `/foo/` redirect,
// which would only arise if the response was generated by a
// `handle` hook or outside the app altogether (since you
// can't declaratively create both routes)
src = src.replace(/\/?$/, '/?');
}

prerendered_redirects.push({
src: src.replace(/\/?$/, '/?'),
src,
headers: {
Location: redirect.location
},
Expand Down

0 comments on commit ad68def

Please sign in to comment.