summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Juan Martín Seery <me@juanm04.com> 2022-04-22 11:03:53 -0300
committerGravatar GitHub <noreply@github.com> 2022-04-22 10:03:53 -0400
commit725c44a762dbc2f45a1d47ffa31b7e6e0b22ff95 (patch)
tree3d1807cdd10e597ae32352cee662a7f072f9224e
parent19667c45f318ec13cdc2b51016f3fa3487b2a32d (diff)
downloadastro-725c44a762dbc2f45a1d47ffa31b7e6e0b22ff95.tar.gz
astro-725c44a762dbc2f45a1d47ffa31b7e6e0b22ff95.tar.zst
astro-725c44a762dbc2f45a1d47ffa31b7e6e0b22ff95.zip
feat(vercel): Support `trailingSlash` (#3176)
-rw-r--r--.changeset/thirty-boxes-shave.md5
-rw-r--r--packages/integrations/vercel/src/index.ts48
2 files changed, 48 insertions, 5 deletions
diff --git a/.changeset/thirty-boxes-shave.md b/.changeset/thirty-boxes-shave.md
new file mode 100644
index 000000000..bb270722c
--- /dev/null
+++ b/.changeset/thirty-boxes-shave.md
@@ -0,0 +1,5 @@
+---
+'@astrojs/vercel': patch
+---
+
+Support trailingSlash
diff --git a/packages/integrations/vercel/src/index.ts b/packages/integrations/vercel/src/index.ts
index 439eeeb04..35d20d42f 100644
--- a/packages/integrations/vercel/src/index.ts
+++ b/packages/integrations/vercel/src/index.ts
@@ -87,11 +87,49 @@ export default function vercel(): AstroIntegration {
version: 3,
basePath: '/',
pages404: false,
- rewrites: staticRoutes.map((route) => ({
- source: route.pathname,
- regex: route.pattern.toString(),
- destination: `/${ENTRYFILE}`,
- })),
+ 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(),