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
+6
View File
@@ -38,6 +38,11 @@ export async function POST(request: NextRequest) {
if (handle.includes('@')) { if (handle.includes('@')) {
const parts = handle.split('@'); const parts = handle.split('@');
senderNodeDomain = parts[parts.length - 1]; senderNodeDomain = parts[parts.length - 1];
} else {
// Try to get from header first
const sourceDomainHeader = request.headers.get('X-Swarm-Source-Domain');
if (sourceDomainHeader) {
senderNodeDomain = sourceDomainHeader;
} else { } else {
// Try handle registry (though we likely don't have it if we don't have the user) // Try handle registry (though we likely don't have it if we don't have the user)
const registryEntry = await db.query.handleRegistry.findFirst({ const registryEntry = await db.query.handleRegistry.findFirst({
@@ -45,6 +50,7 @@ export async function POST(request: NextRequest) {
}); });
if (registryEntry) senderNodeDomain = registryEntry.nodeDomain; if (registryEntry) senderNodeDomain = registryEntry.nodeDomain;
} }
}
if (senderNodeDomain) { if (senderNodeDomain) {
try { try {
+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
}); });