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(vercel-edge): fix route generation #1071

Merged
merged 1 commit into from
Mar 22, 2023

Conversation

smaeda-ks
Copy link
Contributor

It seems routeRules generates invalid routes when using the vercel-edge preset.

This is because nitro only creates pretender functions for the vercel preset:

// Write prerender functions
const rules = Object.entries(nitro.options.routeRules).filter(
([_, value]) => value.cache && (value.cache.swr || value.cache.static)
);
for (const [key, value] of rules) {
if (!value.cache) {
continue;
} // for type support
const funcPrefix = resolve(
nitro.options.output.serverDir,
".." + generateEndpoint(key)
);
await fsp.mkdir(dirname(funcPrefix), { recursive: true });
await fsp.symlink(
"./" + relative(dirname(funcPrefix), nitro.options.output.serverDir),
funcPrefix + ".func",
"junction"
);
let expiration: boolean | number = 60;
if (value.cache.static) {
expiration = false;
} else if (typeof value.cache.swr === "number") {
expiration = value.cache.swr;
}
await writeFile(
funcPrefix + ".prerender-config.json",
JSON.stringify({
expiration,
allowQuery: key.includes("/**") ? ["url"] : undefined,
})
);
}

and the generateEndpoint function isn't considering the vercel-edge preset:

nitro/src/presets/vercel.ts

Lines 226 to 234 in 4585ca8

function generateEndpoint(url: string) {
if (url === "/") {
return "/__nitro-index";
}
return url.includes("/**")
? "/__nitro-" +
withoutLeadingSlash(url.replace(/\/\*\*.*/, "").replace(/[^a-z]/g, "-"))
: url;
}

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codecov
Copy link

codecov bot commented Mar 21, 2023

Codecov Report

Merging #1071 (649f418) into main (7ae95d2) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1071      +/-   ##
==========================================
- Coverage   67.32%   67.32%   -0.01%     
==========================================
  Files          62       62              
  Lines        6292     6295       +3     
  Branches      707      709       +2     
==========================================
+ Hits         4236     4238       +2     
  Misses       2042     2042              
- Partials       14       15       +1     
Impacted Files Coverage Ξ”
src/presets/vercel.ts 76.79% <100.00%> (-0.13%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

Thanks πŸ’―

@pi0 pi0 changed the title fix(vercel): fix route generation for vercel-edge preset fix(vercel-edge): fix route generation Mar 22, 2023
@pi0 pi0 merged commit ac8ca35 into unjs:main Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants