mizzkey/src/server/activitypub/user.ts

28 lines
788 B
TypeScript
Raw Normal View History

2018-04-01 05:33:26 +02:00
import * as express from 'express';
2018-04-01 08:58:49 +02:00
import config from '../../conf';
2018-04-01 12:18:36 +02:00
import context from '../../common/remote/activitypub/renderer/context';
import render from '../../common/remote/activitypub/renderer/person';
2018-04-01 13:07:04 +02:00
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();
2018-04-01 05:43:59 +02:00
app.disable('x-powered-by');
2018-04-01 13:07:04 +02:00
app.get('/@:user', (req, res, next) => {
const accepted = req.accepts(['html', 'application/activity+json', 'application/ld+json']);
2018-04-01 13:07:04 +02:00
if ((['application/activity+json', 'application/ld+json'] as Array<any>).includes(accepted)) {
respond(req, res, next);
} else {
next();
}
});
export default app;