mirror of
https://github.com/withastro/astro.git
synced 2025-03-10 23:01:26 -05:00
feat(vercel): Support trailingSlash
(#3176)
This commit is contained in:
parent
7a57d0874a
commit
f62227f796
1 changed files with 43 additions and 5 deletions
|
@ -87,11 +87,49 @@ export default function vercel(): AstroIntegration {
|
|||
version: 3,
|
||||
basePath: '/',
|
||||
pages404: false,
|
||||
rewrites: staticRoutes.map((route) => ({
|
||||
source: route.pathname,
|
||||
redirects:
|
||||
// Extracted from Next.js v12.1.5
|
||||
_config.trailingSlash === 'always'
|
||||
? [
|
||||
{
|
||||
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) => ({
|
||||
page: `/${ENTRYFILE}`,
|
||||
regex: route.pattern.toString(),
|
||||
|
|
Loading…
Add table
Reference in a new issue