feat(vercel): Support trailingSlash
(#3176)
This commit is contained in:
parent
19667c45f3
commit
725c44a762
2 changed files with 48 additions and 5 deletions
5
.changeset/thirty-boxes-shave.md
Normal file
5
.changeset/thirty-boxes-shave.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@astrojs/vercel': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Support trailingSlash
|
|
@ -87,11 +87,49 @@ export default function vercel(): AstroIntegration {
|
||||||
version: 3,
|
version: 3,
|
||||||
basePath: '/',
|
basePath: '/',
|
||||||
pages404: false,
|
pages404: false,
|
||||||
rewrites: staticRoutes.map((route) => ({
|
redirects:
|
||||||
source: route.pathname,
|
// Extracted from Next.js v12.1.5
|
||||||
regex: route.pattern.toString(),
|
_config.trailingSlash === 'always'
|
||||||
destination: `/${ENTRYFILE}`,
|
? [
|
||||||
})),
|
{
|
||||||
|
source: '/:file((?!\\.well-known(?:/.*)?)(?:[^/]+/)*[^/]+\\.\\w+)/',
|
||||||
|
destination: '/:file',
|
||||||
|
internal: true,
|
||||||
|
statusCode: 308,
|
||||||
|
regex: '^(?:/((?!\\.well-known(?:/.*)?)(?:[^/]+/)*[^/]+\\.\\w+))/$',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: '/:notfile((?!\\.well-known(?:/.*)?)(?:[^/]+/)*[^/\\.]+)',
|
||||||
|
destination: '/:notfile/',
|
||||||
|
internal: true,
|
||||||
|
statusCode: 308,
|
||||||
|
regex: '^(?:/((?!\\.well-known(?:/.*)?)(?:[^/]+/)*[^/\\.]+))$',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: _config.trailingSlash === 'never'
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
source: '/:path+/',
|
||||||
|
destination: '/:path+',
|
||||||
|
internal: true,
|
||||||
|
statusCode: 308,
|
||||||
|
regex: '^(?:/((?:[^/]+?)(?:/(?:[^/]+?))*))/$',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: undefined,
|
||||||
|
rewrites: staticRoutes.map((route) => {
|
||||||
|
let source = route.pathname as string;
|
||||||
|
|
||||||
|
if (_config.trailingSlash === 'always' && !source.endsWith('/')) {
|
||||||
|
source += '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
source,
|
||||||
|
regex: route.pattern.toString(),
|
||||||
|
destination: `/${ENTRYFILE}`,
|
||||||
|
};
|
||||||
|
}),
|
||||||
dynamicRoutes: dynamicRoutes.map((route) => ({
|
dynamicRoutes: dynamicRoutes.map((route) => ({
|
||||||
page: `/${ENTRYFILE}`,
|
page: `/${ENTRYFILE}`,
|
||||||
regex: route.pattern.toString(),
|
regex: route.pattern.toString(),
|
||||||
|
|
Loading…
Reference in a new issue