fix(vercel): trailingSlash
fix for non-html pages (#3185)
* fix(vercel): `trailingSlash` fix for non-html pages * Changeset
This commit is contained in:
parent
22cb4b7b32
commit
eaad17694f
2 changed files with 42 additions and 29 deletions
5
.changeset/swift-houses-itch.md
Normal file
5
.changeset/swift-houses-itch.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@astrojs/vercel': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixed `trailingSlash` for non-HTML pages
|
|
@ -88,39 +88,47 @@ export default function vercel(): AstroIntegration {
|
||||||
basePath: '/',
|
basePath: '/',
|
||||||
pages404: false,
|
pages404: false,
|
||||||
redirects:
|
redirects:
|
||||||
// Extracted from Next.js v12.1.5
|
_config.trailingSlash !== 'ignore'
|
||||||
_config.trailingSlash === 'always'
|
? routes
|
||||||
? [
|
.filter((route) => route.type === 'page' && !route.pathname?.endsWith('/'))
|
||||||
{
|
.map((route) => {
|
||||||
source: '/:file((?!\\.well-known(?:/.*)?)(?:[^/]+/)*[^/]+\\.\\w+)/',
|
const path =
|
||||||
destination: '/:file',
|
'/' +
|
||||||
internal: true,
|
route.segments
|
||||||
statusCode: 308,
|
.map((segments) =>
|
||||||
regex: '^(?:/((?!\\.well-known(?:/.*)?)(?:[^/]+/)*[^/]+\\.\\w+))/$',
|
segments
|
||||||
},
|
.map((part) =>
|
||||||
{
|
part.spread
|
||||||
source: '/:notfile((?!\\.well-known(?:/.*)?)(?:[^/]+/)*[^/\\.]+)',
|
? `:${part.content}*`
|
||||||
destination: '/:notfile/',
|
: part.dynamic
|
||||||
internal: true,
|
? `:${part.content}`
|
||||||
statusCode: 308,
|
: part.content
|
||||||
regex: '^(?:/((?!\\.well-known(?:/.*)?)(?:[^/]+/)*[^/\\.]+))$',
|
)
|
||||||
},
|
.join('')
|
||||||
]
|
)
|
||||||
: _config.trailingSlash === 'never'
|
.join('/');
|
||||||
? [
|
|
||||||
{
|
let source, destination;
|
||||||
source: '/:path+/',
|
|
||||||
destination: '/:path+',
|
if (_config.trailingSlash === 'always') {
|
||||||
internal: true,
|
source = path;
|
||||||
statusCode: 308,
|
destination = path + '/';
|
||||||
regex: '^(?:/((?:[^/]+?)(?:/(?:[^/]+?))*))/$',
|
} else {
|
||||||
},
|
source = path + '/';
|
||||||
]
|
destination = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { source, destination, statusCode: 308 };
|
||||||
|
})
|
||||||
: undefined,
|
: undefined,
|
||||||
rewrites: staticRoutes.map((route) => {
|
rewrites: staticRoutes.map((route) => {
|
||||||
let source = route.pathname as string;
|
let source = route.pathname as string;
|
||||||
|
|
||||||
if (_config.trailingSlash === 'always' && !source.endsWith('/')) {
|
if (
|
||||||
|
route.type === 'page' &&
|
||||||
|
_config.trailingSlash === 'always' &&
|
||||||
|
!source.endsWith('/')
|
||||||
|
) {
|
||||||
source += '/';
|
source += '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue