cleaning and use nuxt-express

This commit is contained in:
les
2019-08-09 01:58:11 +02:00
parent e96880fc92
commit def1be8803
11 changed files with 51 additions and 43 deletions

View File

@@ -67,7 +67,7 @@ const Helpers = {
// TODO: cache
async getActor(url, force=false) {
// try with cache first if not forced
// try with cache first
if (!force && actorCache[url]) return actorCache[url]
const user = await fetch(url, { headers: {'Accept': 'application/jrd+json, application/json'} })
.then(res => {
@@ -84,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) return res.send('Actor not found', 401)
if (!user) return res.status(401).send('Actor not found')
// little hack -> https://github.com/joyent/node-http-signature/pull/83
req.headers.authorization = 'Signature ' + req.headers.signature
@@ -97,7 +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 (!user) return res.status(401).send('Actor not found')
if (httpSignature.verifySignature(parsed, user.publicKey.publicKeyPem)) return next()
// still not valid