diff --git a/.gitignore b/.gitignore index cafaf74a0..7d30b9530 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .env .idea +*.iml .vscode .DS_Store npm-debug.log* diff --git a/backend/src/activitypub/ActivityPub.js b/backend/src/activitypub/ActivityPub.js index bcebf4d49..c02193abd 100644 --- a/backend/src/activitypub/ActivityPub.js +++ b/backend/src/activitypub/ActivityPub.js @@ -22,9 +22,8 @@ let activityPub = null export { activityPub } export default class ActivityPub { - constructor (domain, port, uri) { - if (domain === 'localhost') { this.domain = `${domain}:${port}` } else { this.domain = domain } - this.port = port + constructor (host, uri) { + this.host = host this.dataSource = new NitroDataSource(uri) this.collections = new Collections(this.dataSource) } @@ -33,7 +32,7 @@ export default class ActivityPub { if (!activityPub) { dotenv.config() const url = new URL(process.env.GRAPHQL_URI) - activityPub = new ActivityPub(url.hostname || 'localhost', url.port || 4000, url.origin) + activityPub = new ActivityPub(url.host || 'localhost:4000', url.origin) // integrate into running graphql express server server.express.set('ap', activityPub) @@ -59,7 +58,7 @@ export default class ActivityPub { } }, async (err, response, toActorObject) => { if (err) return reject(err) - debug(`name = ${toActorName}@${this.domain}`) + debug(`name = ${toActorName}@${this.host}`) // save shared inbox toActorObject = JSON.parse(toActorObject) await this.dataSource.addSharedInboxEndpoint(toActorObject.endpoints.sharedInbox) @@ -184,7 +183,7 @@ export default class ActivityPub { } generateStatusId (slug) { - return `http://${this.domain}/activitypub/users/${slug}/status/${uuid()}` + return `https://${this.host}/activitypub/users/${slug}/status/${uuid()}` } async sendActivity (activity) { diff --git a/backend/src/activitypub/utils/activity.js b/backend/src/activitypub/utils/activity.js index 53bcd37ea..a8c525302 100644 --- a/backend/src/activitypub/utils/activity.js +++ b/backend/src/activitypub/utils/activity.js @@ -11,14 +11,14 @@ export function createNoteObject (text, name, id, published) { return { '@context': 'https://www.w3.org/ns/activitystreams', - 'id': `https://${activityPub.domain}/activitypub/users/${name}/status/${createUuid}`, + 'id': `https://${activityPub.host}/activitypub/users/${name}/status/${createUuid}`, 'type': 'Create', - 'actor': `https://${activityPub.domain}/activitypub/users/${name}`, + 'actor': `https://${activityPub.host}/activitypub/users/${name}`, 'object': { - 'id': `https://${activityPub.domain}/activitypub/users/${name}/status/${id}`, + 'id': `https://${activityPub.host}/activitypub/users/${name}/status/${id}`, 'type': 'Note', 'published': published, - 'attributedTo': `https://${activityPub.domain}/activitypub/users/${name}`, + 'attributedTo': `https://${activityPub.host}/activitypub/users/${name}`, 'content': text, 'to': 'https://www.w3.org/ns/activitystreams#Public' } @@ -64,8 +64,8 @@ export async function getActorId (name) { export function sendAcceptActivity (theBody, name, targetDomain, url) { as.accept() - .id(`https://${activityPub.domain}/activitypub/users/${name}/status/` + crypto.randomBytes(16).toString('hex')) - .actor(`https://${activityPub.domain}/activitypub/users/${name}`) + .id(`https://${activityPub.host}/activitypub/users/${name}/status/` + crypto.randomBytes(16).toString('hex')) + .actor(`https://${activityPub.host}/activitypub/users/${name}`) .object(theBody) .prettyWrite((err, doc) => { if (!err) { @@ -79,8 +79,8 @@ export function sendAcceptActivity (theBody, name, targetDomain, url) { export function sendRejectActivity (theBody, name, targetDomain, url) { as.reject() - .id(`https://${activityPub.domain}/activitypub/users/${name}/status/` + crypto.randomBytes(16).toString('hex')) - .actor(`https://${activityPub.domain}/activitypub/users/${name}`) + .id(`https://${activityPub.host}/activitypub/users/${name}/status/` + crypto.randomBytes(16).toString('hex')) + .actor(`https://${activityPub.host}/activitypub/users/${name}`) .object(theBody) .prettyWrite((err, doc) => { if (!err) { diff --git a/backend/src/activitypub/utils/actor.js b/backend/src/activitypub/utils/actor.js index 0b8cc7454..0a3884023 100644 --- a/backend/src/activitypub/utils/actor.js +++ b/backend/src/activitypub/utils/actor.js @@ -6,21 +6,21 @@ export function createActor (name, pubkey) { 'https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1' ], - 'id': `https://${activityPub.domain}/activitypub/users/${name}`, + 'id': `https://${activityPub.host}/activitypub/users/${name}`, 'type': 'Person', 'preferredUsername': `${name}`, 'name': `${name}`, - 'following': `https://${activityPub.domain}/activitypub/users/${name}/following`, - 'followers': `https://${activityPub.domain}/activitypub/users/${name}/followers`, - 'inbox': `https://${activityPub.domain}/activitypub/users/${name}/inbox`, - 'outbox': `https://${activityPub.domain}/activitypub/users/${name}/outbox`, - 'url': `https://${activityPub.domain}/activitypub/@${name}`, + 'following': `https://${activityPub.host}/activitypub/users/${name}/following`, + 'followers': `https://${activityPub.host}/activitypub/users/${name}/followers`, + 'inbox': `https://${activityPub.host}/activitypub/users/${name}/inbox`, + 'outbox': `https://${activityPub.host}/activitypub/users/${name}/outbox`, + 'url': `https://${activityPub.host}/activitypub/@${name}`, 'endpoints': { - 'sharedInbox': `https://${activityPub.domain}/activitypub/inbox` + 'sharedInbox': `https://${activityPub.host}/activitypub/inbox` }, 'publicKey': { - 'id': `https://${activityPub.domain}/activitypub/users/${name}#main-key`, - 'owner': `https://${activityPub.domain}/activitypub/users/${name}`, + 'id': `https://${activityPub.host}/activitypub/users/${name}#main-key`, + 'owner': `https://${activityPub.host}/activitypub/users/${name}`, 'publicKeyPem': pubkey } } @@ -28,12 +28,12 @@ export function createActor (name, pubkey) { export function createWebFinger (name) { return { - 'subject': `acct:${name}@${activityPub.domain}`, + 'subject': `acct:${name}@${activityPub.host}`, 'links': [ { 'rel': 'self', 'type': 'application/activity+json', - 'href': `https://${activityPub.domain}/users/${name}` + 'href': `https://${activityPub.host}/activitypub/users/${name}` } ] } diff --git a/backend/src/activitypub/utils/collection.js b/backend/src/activitypub/utils/collection.js index 4c46adbde..61670bb47 100644 --- a/backend/src/activitypub/utils/collection.js +++ b/backend/src/activitypub/utils/collection.js @@ -5,10 +5,10 @@ const debug = require('debug')('ea:utils:collections') export function createOrderedCollection (name, collectionName) { return { '@context': 'https://www.w3.org/ns/activitystreams', - 'id': `https://${activityPub.domain}/activitypub/users/${name}/${collectionName}`, + 'id': `https://${activityPub.host}/activitypub/users/${name}/${collectionName}`, 'summary': `${name}s ${collectionName} collection`, 'type': 'OrderedCollection', - 'first': `https://${activityPub.domain}/activitypub/users/${name}/${collectionName}?page=true`, + 'first': `https://${activityPub.host}/activitypub/users/${name}/${collectionName}?page=true`, 'totalItems': 0 } } @@ -16,11 +16,11 @@ export function createOrderedCollection (name, collectionName) { export function createOrderedCollectionPage (name, collectionName) { return { '@context': 'https://www.w3.org/ns/activitystreams', - 'id': `https://${activityPub.domain}/activitypub/users/${name}/${collectionName}?page=true`, + 'id': `https://${activityPub.host}/activitypub/users/${name}/${collectionName}?page=true`, 'summary': `${name}s ${collectionName} collection`, 'type': 'OrderedCollectionPage', 'totalItems': 0, - 'partOf': `https://${activityPub.domain}/activitypub/users/${name}/${collectionName}`, + 'partOf': `https://${activityPub.host}/activitypub/users/${name}/${collectionName}`, 'orderedItems': [] } } diff --git a/backend/src/activitypub/utils/index.js b/backend/src/activitypub/utils/index.js index c48e15e3d..4ae2b073f 100644 --- a/backend/src/activitypub/utils/index.js +++ b/backend/src/activitypub/utils/index.js @@ -20,12 +20,12 @@ export function extractIdFromActivityId (uri) { return splitted[splitted.indexOf('status') + 1] } -export function constructIdFromName (name, fromDomain = activityPub.domain) { +export function constructIdFromName (name, fromDomain = activityPub.host) { return `http://${fromDomain}/activitypub/users/${name}` } export function extractDomainFromUrl (url) { - return new URL(url).hostname + return new URL(url).host } export function throwErrorIfApolloErrorOccurred (result) { @@ -76,7 +76,7 @@ export function signAndSend (activity, fromName, targetDomain, url) { 'Host': targetDomain, 'Date': date, 'Signature': createSignature({ privateKey, - keyId: `http://${activityPub.domain}/activitypub/users/${fromName}#main-key`, + keyId: `http://${activityPub.host}/activitypub/users/${fromName}#main-key`, url, headers: { 'Host': targetDomain, diff --git a/backend/src/index.js b/backend/src/index.js index c91f3e9be..7ed7bf70a 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -12,6 +12,6 @@ const serverConfig = { const server = createServer() server.start(serverConfig, options => { /* eslint-disable-next-line no-console */ - console.log(`Server ready at ${process.env.GRAPHQL_URI} 🚀`) + console.log(`Server ready at ${process.env.CLIENT_URI} 🚀`) ActivityPub.init(server) }) diff --git a/backend/src/middleware/activityPubMiddleware.js b/backend/src/middleware/activityPubMiddleware.js index 6c737faff..dcb5ae93c 100644 --- a/backend/src/middleware/activityPubMiddleware.js +++ b/backend/src/middleware/activityPubMiddleware.js @@ -49,7 +49,7 @@ export default { CreateUser: async (resolve, root, args, context, info) => { const keys = generateRsaKeyPair() Object.assign(args, keys) - args.actorId = `${process.env.GRAPHQL_URI}/activitypub/users/${args.slug}` + args.actorId = `${activityPub.host}/activitypub/users/${args.slug}` return resolve(root, args, context, info) } } diff --git a/backend/test/features/webfinger.feature b/backend/test/features/webfinger.feature index e7d1ace04..c9f9e587b 100644 --- a/backend/test/features/webfinger.feature +++ b/backend/test/features/webfinger.feature @@ -19,7 +19,7 @@ Feature: Webfinger discovery { "rel": "self", "type": "application/activity+json", - "href": "https://localhost:4123/users/peter-lustiger" + "href": "https://localhost:4123/activitypub/users/peter-lustiger" } ] } diff --git a/webapp/nuxt.config.js b/webapp/nuxt.config.js index 70ab6333d..80b17a26c 100644 --- a/webapp/nuxt.config.js +++ b/webapp/nuxt.config.js @@ -121,12 +121,21 @@ module.exports = { proxy: true }, proxy: { + '/.well-known/webfinger': { + target: process.env.GRAPHQL_URI || 'http://localhost:4000', + toProxy: true // cloudflare needs that + }, + '/activityPub': { + // make this configurable (nuxt-dotenv) + target: process.env.GRAPHQL_URI || 'http://localhost:4000', + pathRewrite: { '^/activityPub': '' }, + toProxy: true // cloudflare needs that + }, '/api': { // make this configurable (nuxt-dotenv) target: process.env.GRAPHQL_URI || 'http://localhost:4000', pathRewrite: { '^/api': '' }, toProxy: true, // cloudflare needs that - changeOrigin: true, headers: { Accept: 'application/json', 'X-UI-Request': true,