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