summaryrefslogtreecommitdiff
path: root/src/server/activitypub/user.ts
blob: f0549745105be0b109ecaafb015c0e627f3a767b (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
import * as express from 'express';
import config from '../../config';
import context from '../../remote/activitypub/renderer/context';
import render from '../../remote/activitypub/renderer/person';
import withUser from './with-user';

const respond = withUser(username => `${config.url}/@${username}`, (user, req, res) => {
	const rendered = render(user);
	rendered['@context'] = context;

	res.json(rendered);
});

const app = express.Router();

app.get('/@:user', (req, res, next) => {
	const accepted = req.accepts(['html', 'application/activity+json', 'application/ld+json']);

	if ((['application/activity+json', 'application/ld+json'] as any[]).includes(accepted)) {
		respond(req, res, next);
	} else {
		next();
	}
});

export default app;