-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathactor.js
More file actions
70 lines (65 loc) · 2.06 KB
/
Copy pathactor.js
File metadata and controls
70 lines (65 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* Actor endpoint handler
* Returns ActivityPub Actor JSON-LD for content negotiation
*/
/**
* Create actor handler
* @param {object} config - AP configuration
* @param {object} keypair - RSA keypair
* @returns {Function} Handler function
*/
export function createActorHandler(config, keypair) {
return (request) => {
// Check various proxy headers for protocol detection
let protocol = request.headers['x-forwarded-proto']
if (!protocol) {
// Cloudflare uses cf-visitor: {"scheme":"https"}
const cfVisitor = request.headers['cf-visitor']
if (cfVisitor) {
try {
const parsed = JSON.parse(cfVisitor)
protocol = parsed.scheme
} catch { /* ignore */ }
}
}
// If still no protocol and hostname looks like a public domain, assume https
const host = request.headers['x-forwarded-host'] || request.hostname
if (!protocol && host && !host.match(/^(localhost|127\.|192\.168\.|10\.)/)) {
protocol = 'https'
}
protocol = protocol || request.protocol
const baseUrl = `${protocol}://${host}`
const profileUrl = `${baseUrl}/profile/card.jsonld`
const actorId = `${profileUrl}#me`
const actor = {
'@context': [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1'
],
type: 'Person',
id: actorId,
url: profileUrl,
preferredUsername: config.username,
name: config.displayName,
summary: config.summary ? `<p>${config.summary}</p>` : '',
inbox: `${profileUrl}/inbox`,
outbox: `${profileUrl}/outbox`,
followers: `${profileUrl}/followers`,
following: `${profileUrl}/following`,
endpoints: {
sharedInbox: `${baseUrl}/inbox`
},
publicKey: {
id: `${profileUrl}#main-key`,
owner: actorId,
publicKeyPem: keypair.publicKey
}
}
// Add Nostr identity linking via alsoKnownAs
if (config.nostrPubkey) {
actor.alsoKnownAs = [`did:nostr:${config.nostrPubkey}`]
}
return actor
}
}
export default { createActorHandler }