feat: Use X-Swarm-Source-Domain header to identify the sender's node domain in chat messages.

This commit is contained in:
Christomatt
2026-01-29 06:58:17 +01:00
parent 645e9a6670
commit 1f115d569f
2 changed files with 15 additions and 6 deletions
+11 -5
View File
@@ -39,11 +39,17 @@ export async function POST(request: NextRequest) {
const parts = handle.split('@'); const parts = handle.split('@');
senderNodeDomain = parts[parts.length - 1]; senderNodeDomain = parts[parts.length - 1];
} else { } else {
// Try handle registry (though we likely don't have it if we don't have the user) // Try to get from header first
const registryEntry = await db.query.handleRegistry.findFirst({ const sourceDomainHeader = request.headers.get('X-Swarm-Source-Domain');
where: eq(handleRegistry.did, did) if (sourceDomainHeader) {
}); senderNodeDomain = sourceDomainHeader;
if (registryEntry) senderNodeDomain = registryEntry.nodeDomain; } 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) { if (senderNodeDomain) {
+4 -1
View File
@@ -165,7 +165,10 @@ export async function POST(request: NextRequest) {
const protocol = targetDomain.includes('localhost') ? 'http' : 'https'; const protocol = targetDomain.includes('localhost') ? 'http' : 'https';
const res = await fetch(`${protocol}://${targetDomain}/api/chat/receive`, { const res = await fetch(`${protocol}://${targetDomain}/api/chat/receive`, {
method: 'POST', 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 body: JSON.stringify(signedAction) // Forward the user's signed intent
}); });