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
3 changes: 2 additions & 1 deletion src/lib/site-offline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ describe('bittorrented.com offline, invite only', () => {
for (const path of ['/', '/search?q=x', '/dht', '/torrents/abc', '/pricing', '/account']) {
const res = await get(path);
expect(res.status).toBe(307);
expect(res.headers.get('location')).toMatch(/\/invite-only$/);
// Absolute, or Next.js answers 500 "Invalid URL" in production.
expect(res.headers.get('location')).toBe('https://bittorrented.com/invite-only');
}
});

Expand Down
6 changes: 4 additions & 2 deletions src/lib/site-offline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ export function openWhileInviteOnly(pathname: string): boolean {
* Pages go to the invite-only screen; the API answers 503 so clients and search
* engines treat it as temporary.
*/
export function offlineResponse(pathname: string): Response {
export function offlineResponse(pathname: string, requestUrl: string | URL): Response {
const headers = { 'cache-control': 'no-store' };
if (pathname.startsWith('/api/')) {
return Response.json(
{ error: 'BitTorrented is invite only and not open yet.' },
{ status: 503, headers: { ...headers, 'retry-after': '86400' } }
);
}
return new Response(null, { status: 307, headers: { ...headers, location: INVITE_ONLY_PAGE } });
// Absolute: Next.js answers 500 "Invalid URL" for a relative Location from the proxy.
const location = new URL(INVITE_ONLY_PAGE, requestUrl).toString();
return new Response(null, { status: 307, headers: { ...headers, location } });
}
2 changes: 1 addition & 1 deletion src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ export async function proxy(request: NextRequest): Promise<Response> {
!openWhileInviteOnly(request.nextUrl.pathname) &&
!(await isAdmin())
) {
return asNext(offlineResponse(request.nextUrl.pathname));
return asNext(offlineResponse(request.nextUrl.pathname, request.url));
}

// --- 0b. Legal mode: only reviewed features are served (see src/lib/legal-mode.ts) ---
Expand Down
Loading