diff --git a/src/app/api/chat/receive/route.ts b/src/app/api/chat/receive/route.ts index f3d16ca..6e8021d 100644 --- a/src/app/api/chat/receive/route.ts +++ b/src/app/api/chat/receive/route.ts @@ -39,11 +39,17 @@ export async function POST(request: NextRequest) { const parts = handle.split('@'); senderNodeDomain = parts[parts.length - 1]; } else { - // Try handle registry (though we likely don't have it if we don't have the user) - const registryEntry = await db.query.handleRegistry.findFirst({ - where: eq(handleRegistry.did, did) - }); - if (registryEntry) senderNodeDomain = registryEntry.nodeDomain; + // Try to get from header first + const sourceDomainHeader = request.headers.get('X-Swarm-Source-Domain'); + if (sourceDomainHeader) { + senderNodeDomain = sourceDomainHeader; + } else { + // Try handle registry (though we likely don't have it if we don't have the user) + const registryEntry = await db.query.handleRegistry.findFirst({ + where: eq(handleRegistry.did, did) + }); + if (registryEntry) senderNodeDomain = registryEntry.nodeDomain; + } } if (senderNodeDomain) { diff --git a/src/app/api/chat/send/route.ts b/src/app/api/chat/send/route.ts index 2aa29c1..e0a1255 100644 --- a/src/app/api/chat/send/route.ts +++ b/src/app/api/chat/send/route.ts @@ -165,7 +165,10 @@ export async function POST(request: NextRequest) { const protocol = targetDomain.includes('localhost') ? 'http' : 'https'; const res = await fetch(`${protocol}://${targetDomain}/api/chat/receive`, { method: 'POST', - headers: { 'Content-Type': 'application/json' }, + headers: { + 'Content-Type': 'application/json', + 'X-Swarm-Source-Domain': process.env.NEXT_PUBLIC_NODE_DOMAIN || '' + }, body: JSON.stringify(signedAction) // Forward the user's signed intent });