Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@ describe('getRedirects', () => {
);
});

it('redirects /certificates/:session_id to studio.code.org/api/hour/certificates/:session_id', () => {
const sessionID = '_1_537adb90bcf397109ef4358f4c66c493';
const req = createMockRequest(`/certificates/${sessionID}`);
getRedirects(req);
expect(getCachedRedirectResponse).toHaveBeenCalledWith(
new URL(`/api/hour/certificates/${sessionID}`, 'https://studio.code.org'),
{status: 308},
);
});

it('does not redirect /certificates/blank to studio.code.org/api/hour/certificates/:session_id', () => {
const req = createMockRequest('/certificates/blank');
getRedirects(req);
expect(getCachedRedirectResponse).not.toHaveBeenCalledWith(
new URL('/api/hour/certificates/blank', 'https://studio.code.org'),
{status: 308},
);
});

it('returns undefined for unrelated paths', () => {
const req = createMockRequest('/other/path');
const result = getRedirects(req);
Expand Down
12 changes: 12 additions & 0 deletions apps/marketing/src/middleware/redirects/corporate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,16 @@ export function getRedirects(request: NextRequest) {

return getCachedRedirectResponse(redirectUrl, {status: 308});
}

// Permanently redirect /certificates/:session_id to studio.code.org/api/hour/certificates/:session_id
// The :session_id parameter always starts with an underscore (e.g., "_1_537adb90bcf397109ef4358f4c66c493")
if (pathParts[0] === 'certificates' && pathParts[1].startsWith('_')) {
const restOfPath = pathParts.slice(1).join('/');
const redirectUrl = new URL(
`/api/hour/certificates/${restOfPath}`,
getStudioBaseUrl(),
);

return getCachedRedirectResponse(redirectUrl, {status: 308});
}
}
Loading