fix(share): ensure redirect URL uses x-forwarded-host and proto instead of container internal 0.0.0.0
This commit is contained in:
1 parent
fb3c01c6ae
commit
c739f74055
2 files changed
+33
-8
No files matched your search
@@ -18,6 +18,17 @@ import {
|
|||||||
} from '@/lib/storage';
|
} from '@/lib/storage';
|
||||||
import { applyAutoSortToNote } from '@/lib/autoSort';
|
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 = {
|
const corsHeaders = {
|
||||||
'Access-Control-Allow-Origin': '*',
|
'Access-Control-Allow-Origin': '*',
|
||||||
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
|
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
|
||||||
@@ -194,7 +205,7 @@ export async function POST(req: NextRequest) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (isShareTarget) {
|
if (isShareTarget) {
|
||||||
return NextResponse.redirect(new URL(`/?noteId=${clippedId}&shared=1`, req.url), 303);
|
return NextResponse.redirect(getRedirectUrl(req, clippedId), 303);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
@@ -299,7 +310,7 @@ export async function POST(req: NextRequest) {
|
|||||||
await applyAutoSortToNote(note.id, userId).catch(() => {});
|
await applyAutoSortToNote(note.id, userId).catch(() => {});
|
||||||
|
|
||||||
if (isShareTarget) {
|
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(
|
return NextResponse.json(
|
||||||
@@ -380,7 +391,7 @@ export async function GET(req: NextRequest) {
|
|||||||
await applyAutoSortToNote(noteId, userId).catch(() => {});
|
await applyAutoSortToNote(noteId, userId).catch(() => {});
|
||||||
|
|
||||||
if (sp.get('redirect') === '1' || sp.get('source') === 'share-target') {
|
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(
|
return NextResponse.json(
|
||||||
|
|||||||
+19
-5
@@ -24,6 +24,20 @@ function extractUrl(text: string): { extractedUrl: string | null; remainingText:
|
|||||||
return { extractedUrl, 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) {
|
export async function GET(req: NextRequest) {
|
||||||
try {
|
try {
|
||||||
const userId = await getCurrentUserId();
|
const userId = await getCurrentUserId();
|
||||||
@@ -81,10 +95,10 @@ export async function GET(req: NextRequest) {
|
|||||||
|
|
||||||
await applyAutoSortToNote(noteId, userId).catch(() => {});
|
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) {
|
} catch (err) {
|
||||||
console.error('GET /share error:', 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'],
|
tags: ['inbox', 'web-clip'],
|
||||||
});
|
});
|
||||||
await applyAutoSortToNote(clippedId, userId).catch(() => {});
|
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) {
|
} catch (e) {
|
||||||
console.warn('URL clipping failed in /share, falling back to basic link note:', 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(() => {});
|
await applyAutoSortToNote(note.id, userId).catch(() => {});
|
||||||
|
|
||||||
// 5. Redirect browser / Android WebAPK straight into Everclone displaying the new note
|
// 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) {
|
} catch (err) {
|
||||||
console.error('POST /share error:', 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user