summaryrefslogtreecommitdiff
path: root/src/server/activitypub/inbox.ts
blob: 5de843385009217acb2a4aad9b71d389a5c5e672 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import * as bodyParser from 'body-parser';
import * as express from 'express';
import { parseRequest } from 'http-signature';
import queue from '../../queue';

const app = express();

app.disable('x-powered-by');

app.post('/@:user/inbox', bodyParser.json({
	type() {
		return true;
	}
}), async (req, res) => {
	let signature;

	req.headers.authorization = 'Signature ' + req.headers.signature;

	try {
		signature = parseRequest(req);
	} catch (exception) {
		return res.sendStatus(401);
	}

	queue.create('http', {
		type: 'processInbox',
		inbox: req.body,
		signature,
	}).save();

	return res.status(202).end();
});

export default app;