Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/little-doors-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/vercel': patch
---

Fixes a bug that caused external redirects to fail
12 changes: 8 additions & 4 deletions packages/integrations/vercel/src/lib/redirects.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import nodePath from 'node:path';
import { removeLeadingForwardSlash } from '@astrojs/internal-helpers/path';
import { isRemotePath, removeLeadingForwardSlash } from '@astrojs/internal-helpers/path';
import type { AstroConfig, IntegrationResolvedRoute, RoutePart } from 'astro';

import type { Redirect } from '@vercel/routing-utils';
Expand Down Expand Up @@ -92,10 +92,14 @@ function getRedirectLocation(route: IntegrationResolvedRoute, config: AstroConfi
return pathJoin(config.base, pattern);
}

if (typeof route.redirect === 'object') {
return pathJoin(config.base, route.redirect.destination);
const destination =
typeof route.redirect === 'object' ? route.redirect.destination : (route.redirect ?? '');

if (isRemotePath(destination)) {
return destination;
}
return pathJoin(config.base, route.redirect || '');

return pathJoin(config.base, destination);
}

function getRedirectStatus(route: IntegrationResolvedRoute): number {
Expand Down
8 changes: 8 additions & 0 deletions packages/integrations/vercel/test/redirects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ describe('Redirects', () => {
status: 302,
destination: '/',
},
'/four': {
status: 302,
destination: 'http://example.com',
},
'/blog/[...slug]': '/team/articles/[...slug]',
'/Basic/http-2-0.html': '/posts/http2',
},
Expand Down Expand Up @@ -43,6 +47,10 @@ describe('Redirects', () => {
const threeRoute = config.routes.find((r) => r.src === '^/three$');
assert.equal(threeRoute.headers.Location, '/');
assert.equal(threeRoute.status, 302);

const fourRoute = config.routes.find((r) => r.src === '^/four$');
assert.equal(fourRoute.headers.Location, 'http://example.com');
assert.equal(fourRoute.status, 302);
});

it('define redirects for static files', async () => {
Expand Down