fix(share): ensure redirect URL uses x-forwarded-host and proto instead of container internal 0.0.0.0

This commit is contained in:
chrisf committed 2026-10-22 19:29:53 -06:00
1 parent fb3c01c6ae
commit c739f74055
2 files changed
+33 -8

No files matched your search

+14 -3
View File
@@ -18,6 +18,17 @@ import {
} from '@/lib/storage';
import { applyAutoSortToNote } from '@/lib/autoSort';
function getRedirectUrl(req: NextRequest, noteId: string): URL {
const host =
req.headers.get('x-forwarded-host') ||
req.headers.get('host') ||
'everclone.vloser.us';
const proto =
req.headers.get('x-forwarded-proto') ||
'https';
return new URL(`${proto}://${host}/?noteId=${noteId}&shared=1`);
}
const corsHeaders = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
@@ -194,7 +205,7 @@ export async function POST(req: NextRequest) {
});
if (isShareTarget) {
return NextResponse.redirect(new URL(`/?noteId=${clippedId}&shared=1`, req.url), 303);
return NextResponse.redirect(getRedirectUrl(req, clippedId), 303);
}
return NextResponse.json(
@@ -299,7 +310,7 @@ export async function POST(req: NextRequest) {
await applyAutoSortToNote(note.id, userId).catch(() => {});
if (isShareTarget) {
return NextResponse.redirect(new URL(`/?noteId=${note.id}&shared=1`, req.url), 303);
return NextResponse.redirect(getRedirectUrl(req, note.id), 303);
}
return NextResponse.json(
@@ -380,7 +391,7 @@ export async function GET(req: NextRequest) {
await applyAutoSortToNote(noteId, userId).catch(() => {});
if (sp.get('redirect') === '1' || sp.get('source') === 'share-target') {
return NextResponse.redirect(new URL(`/?noteId=${noteId}&shared=1`, req.url), 303);
return NextResponse.redirect(getRedirectUrl(req, noteId), 303);
}
return NextResponse.json(
+19 -5
View File
@@ -24,6 +24,20 @@ function extractUrl(text: string): { extractedUrl: string | null; remainingText:
return { extractedUrl, remainingText };
}
function getRedirectUrl(req: NextRequest, noteId?: string, isError?: boolean): URL {
const host =
req.headers.get('x-forwarded-host') ||
req.headers.get('host') ||
'everclone.vloser.us';
const proto =
req.headers.get('x-forwarded-proto') ||
'https';
if (isError) {
return new URL(`${proto}://${host}/?shared_error=1`);
}
return new URL(`${proto}://${host}/?noteId=${noteId}&shared=1`);
}
export async function GET(req: NextRequest) {
try {
const userId = await getCurrentUserId();
@@ -81,10 +95,10 @@ export async function GET(req: NextRequest) {
await applyAutoSortToNote(noteId, userId).catch(() => {});
return NextResponse.redirect(new URL(`/?noteId=${noteId}&shared=1`, req.url), 303);
return NextResponse.redirect(getRedirectUrl(req, noteId), 303);
} catch (err) {
console.error('GET /share error:', err);
return NextResponse.redirect(new URL('/?shared_error=1', req.url), 303);
return NextResponse.redirect(getRedirectUrl(req, undefined, true), 303);
}
}
@@ -150,7 +164,7 @@ export async function POST(req: NextRequest) {
tags: ['inbox', 'web-clip'],
});
await applyAutoSortToNote(clippedId, userId).catch(() => {});
return NextResponse.redirect(new URL(`/?noteId=${clippedId}&shared=1`, req.url), 303);
return NextResponse.redirect(getRedirectUrl(req, clippedId), 303);
} catch (e) {
console.warn('URL clipping failed in /share, falling back to basic link note:', e);
}
@@ -249,9 +263,9 @@ export async function POST(req: NextRequest) {
await applyAutoSortToNote(note.id, userId).catch(() => {});
// 5. Redirect browser / Android WebAPK straight into Everclone displaying the new note
return NextResponse.redirect(new URL(`/?noteId=${note.id}&shared=1`, req.url), 303);
return NextResponse.redirect(getRedirectUrl(req, note.id), 303);
} catch (err) {
console.error('POST /share error:', err);
return NextResponse.redirect(new URL('/?shared_error=1', req.url), 303);
return NextResponse.redirect(getRedirectUrl(req, undefined, true), 303);
}
}