feat: Use X-Swarm-Source-Domain header to identify the sender's node domain in chat messages.
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
@@ -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
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user