diff --git a/api/src/activity/index.js b/api/src/activity/index.js new file mode 100644 index 0000000..09b873e --- /dev/null +++ b/api/src/activity/index.js @@ -0,0 +1,11 @@ +global.replaceImpl = (funcs, name, withFunc) => { + for (var i = 0; i < funcs.length; i++) + if (funcs[i].name === name) + funcs[i] = withFunc +} + +module.exports = { + rewriteImplementations: () => { + require('./well-known.js').init() + }, +} diff --git a/api/src/activity/well-known.js b/api/src/activity/well-known.js new file mode 100644 index 0000000..3d0bfef --- /dev/null +++ b/api/src/activity/well-known.js @@ -0,0 +1,28 @@ +module.exports = { + init: () => { + replaceImpl(apex.net.webfinger.get, 'respondWebfinger', (req, res, next) => { + const resource = req.query.resource + const actorObj = res.locals.apex.target + if (!actorObj) { + return res.status(404).send(`${resource} not found`) + } + const profilePage = `https://${apex.domain}/@${actorObj.preferredUsername[0]}` + return res.json({ + subject: resource, + aliases: [ profilePage, actorObj.id ], + links: [ + { + rel: 'http://webfinger.net/rel/profile-page', + type: 'text/html', + href: profilePage + }, + { + rel: 'self', + type: 'application/activity+json', + href: actorObj.id + } + ] + }) + }) + }, +} diff --git a/api/src/server.js b/api/src/server.js index 174efe3..75bb363 100644 --- a/api/src/server.js +++ b/api/src/server.js @@ -1,5 +1,6 @@ const express = require('express') const ActivitypubExpress = require('activitypub-express') +const activity = require('./activity/index.js') const port = 8080 const app = express() @@ -43,6 +44,7 @@ app.use(require('cookie-parser')()) app.use(bodyParser.urlencoded({ extended: true })) // define routes using prepacakged middleware collections +activity.rewriteImplementations() app.route(routes.inbox) .get(apex.net.inbox.get) .post(apex.net.inbox.post)