From 2c3f8e55d6df4fb401858e0527ae717fa9ebc851 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Thu, 10 Jan 2019 16:57:11 -0700 Subject: [PATCH] Add optional endpoints for webfinger and actor --- routes/activitypub/get_actor.js | 27 +++++++++++++++++++++++++++ routes/activitypub/get_webfinger.js | 19 +++++++++++++++++++ server.js | 5 +++++ settings.example.json | 5 ++++- 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 routes/activitypub/get_actor.js create mode 100644 routes/activitypub/get_webfinger.js diff --git a/routes/activitypub/get_actor.js b/routes/activitypub/get_actor.js new file mode 100644 index 0000000..999b647 --- /dev/null +++ b/routes/activitypub/get_actor.js @@ -0,0 +1,27 @@ +const settings = require('../../settings.json'); + +module.exports = function (app) { + app.server.get('/activitypub/actor', function (req, res) { + const actor = JSON.stringify({ + '@context': [ + 'https://www.w3.org/ns/activitystreams', + 'https://w3id.org/security/v1', + ], + + id: `https://${settings.domain}/activitypub/actor`, + type: 'Person', + preferredUsername: 'shelf', + inbox: `https://${settings.domain}/activitypub/inbox`, + outbox: `https://${settings.domain}/activitypub/outbox`, + + publicKey: { + id: `https://${settings.domain}/activitypub/actor#main-key`, + owner: `https://${settings.domain}/activitypub/actor`, + publicKeyPem: settings.publicKey, + } + }); + + res.setHeader('Content-Type', 'application/activity+json'); + res.send(actor); + }); +} \ No newline at end of file diff --git a/routes/activitypub/get_webfinger.js b/routes/activitypub/get_webfinger.js new file mode 100644 index 0000000..ebd66ec --- /dev/null +++ b/routes/activitypub/get_webfinger.js @@ -0,0 +1,19 @@ +const settings = require('../../settings.json'); + +module.exports = function (app) { + app.server.get('/.well-known/webfinger', function (req, res) { + const webfinger = JSON.stringify({ + subject: `acct:shelf@${settings.domain}`, + links: [ + { + rel: 'self', + type: 'application/activity+json', + href: `https://${settings.domain}/activitypub/actor`, + } + ] + }); + + res.setHeader('Content-Type', 'application/activity+json'); + res.send(webfinger); + }); +} \ No newline at end of file diff --git a/server.js b/server.js index 31de42f..98e68dd 100644 --- a/server.js +++ b/server.js @@ -50,6 +50,11 @@ function Server () { require('./routes/post_tools')(this); require('./routes/socketio')(this); + + if (settings.federate) { + require('./routes/activitypub/get_webfinger')(this); + require('./routes/activitypub/get_actor')(this); + } } Server.prototype.replaceBodyWithTooManyBooksWarning = function (body) { diff --git a/settings.example.json b/settings.example.json index 11c442f..73bbe47 100644 --- a/settings.example.json +++ b/settings.example.json @@ -13,5 +13,8 @@ "sslPrivateKey": null, "sslCertificate": null, "sslCertificateAuthority": null, - "forceHTTPS": false + "forceHTTPS": false, + "federate": true, + "domain": "localhost", + "publicKey": null } \ No newline at end of file