mirror of
https://github.com/withastro/astro.git
synced 2025-02-17 22:44:24 -05:00
fix(vercel): trailing slash conflict (#10082)
This commit is contained in:
parent
77e784d6aa
commit
2ffc5721bc
2 changed files with 26 additions and 0 deletions
5
.changeset/breezy-pets-dream.md
Normal file
5
.changeset/breezy-pets-dream.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"@astrojs/vercel": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Prevents infinite redirects when Astro `trailingSlash` configuration is set to `"always"` and "vercel.json" `trailingSlash` configuration is set to `true`
|
|
@ -9,6 +9,7 @@ import { AstroError } from 'astro/errors';
|
||||||
import glob from 'fast-glob';
|
import glob from 'fast-glob';
|
||||||
import { basename } from 'node:path';
|
import { basename } from 'node:path';
|
||||||
import { pathToFileURL } from 'node:url';
|
import { pathToFileURL } from 'node:url';
|
||||||
|
import { existsSync, readFileSync } from 'node:fs';
|
||||||
import {
|
import {
|
||||||
getAstroImageConfig,
|
getAstroImageConfig,
|
||||||
getDefaultImageConfig,
|
getDefaultImageConfig,
|
||||||
|
@ -222,6 +223,26 @@ export default function vercelServerless({
|
||||||
injectScript('page', 'import "@astrojs/vercel/speed-insights"');
|
injectScript('page', 'import "@astrojs/vercel/speed-insights"');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const vercelConfigPath = new URL('vercel.json', config.root);
|
||||||
|
if (existsSync(vercelConfigPath)) {
|
||||||
|
try {
|
||||||
|
const vercelConfig = JSON.parse(readFileSync(vercelConfigPath, 'utf-8'));
|
||||||
|
if (vercelConfig.trailingSlash === true && config.trailingSlash === 'always') {
|
||||||
|
logger.warn(
|
||||||
|
'\n' +
|
||||||
|
`\tYour "vercel.json" \`trailingSlash\` configuration (set to \`true\`) will conflict with your Astro \`trailinglSlash\` configuration (set to \`"always"\`).\n` +
|
||||||
|
`\tThis would cause infinite redirects under certain conditions and throw an \`ERR_TOO_MANY_REDIRECTS\` error.\n` +
|
||||||
|
`\tTo prevent this, your Astro configuration is updated to \`"ignore"\` during builds.\n`
|
||||||
|
);
|
||||||
|
updateConfig({
|
||||||
|
trailingSlash: 'ignore',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (_err) {
|
||||||
|
logger.warn(`Your "vercel.json" config is not a valid json file.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateConfig({
|
updateConfig({
|
||||||
outDir: new URL('./.vercel/output/', config.root),
|
outDir: new URL('./.vercel/output/', config.root),
|
||||||
build: {
|
build: {
|
||||||
|
|
Loading…
Add table
Reference in a new issue