diff --git a/server/api/index.js b/server/api/index.js index 74d5c630..8fdfcacf 100644 --- a/server/api/index.js +++ b/server/api/index.js @@ -99,7 +99,6 @@ api.get('/export/:type', exportController.export) // get events in this range api.get('/event/:month/:year', eventController.getAll) -// api.get('/event/:month/:year', eventController.getAfter) // Handle 404 api.use(function(req, res) { diff --git a/server/federation/follows.js b/server/federation/follows.js index 16d5daf4..31b7bad0 100644 --- a/server/federation/follows.js +++ b/server/federation/follows.js @@ -11,7 +11,7 @@ module.exports = { if (typeof body.object !== 'string') return const username = body.object.replace(`${config.baseurl}/federation/u/`, '') const user = await User.findOne({ where: { username }}) - if (!user) return res.sendStatus(404) + if (!user) return res.status(404).send('User not found') // check for duplicate if (user.followers.indexOf(body.actor) === -1) { diff --git a/server/federation/helpers.js b/server/federation/helpers.js index 2218acdc..5fadc63e 100644 --- a/server/federation/helpers.js +++ b/server/federation/helpers.js @@ -70,10 +70,12 @@ const Helpers = { // try with cache first if not forced if (!force && actorCache[url]) return actorCache[url] const user = await fetch(url, { headers: {'Accept': 'application/jrd+json, application/json'} }) - .then(res => res.json()) - .catch(e => { - debug(e) - return false + .then(res => { + if (!res.ok) { + debug('[ERR] Actor %s => %s', url, res.statusText) + return false + } + return res.json() }) actorCache[url] = user return user @@ -82,7 +84,7 @@ const Helpers = { // ref: https://blog.joinmastodon.org/2018/07/how-to-make-friends-and-verify-requests/ async verifySignature(req, res, next) { let user = await Helpers.getActor(req.body.actor) - if (!user) res.send('Actor not found', 401) + if (!user) return res.send('Actor not found', 401) // little hack -> https://github.com/joyent/node-http-signature/pull/83 req.headers.authorization = 'Signature ' + req.headers.signature @@ -95,6 +97,7 @@ const Helpers = { // signature not valid, try without cache user = await Helpers.getActor(req.body.actor, true) + if (!user) return res.send('Actor not found', 401) if (httpSignature.verifySignature(parsed, user.publicKey.publicKeyPem)) return next() // still not valid diff --git a/server/federation/index.js b/server/federation/index.js index f80ad58d..2c998000 100644 --- a/server/federation/index.js +++ b/server/federation/index.js @@ -63,7 +63,7 @@ router.post('/u/:name/inbox', Helpers.verifySignature, async (req, res) => { // this is a reply if (b.object.type === 'Note' && b.object.inReplyTo) { await Comments.create(b) - res.sendStatus(201) + res.status(201).send() } else { console.error('Create what? ', b.object.type) }