2018-04-01 15:58:49 +09:00
|
|
|
import * as bodyParser from 'body-parser';
|
|
|
|
import * as express from 'express';
|
2018-04-02 18:36:47 +09:00
|
|
|
import { parseRequest } from 'http-signature';
|
2018-04-01 15:58:49 +09:00
|
|
|
import queue from '../../queue';
|
|
|
|
|
|
|
|
const app = express();
|
2018-04-02 17:11:14 +09:00
|
|
|
|
2018-04-01 15:58:49 +09:00
|
|
|
app.disable('x-powered-by');
|
|
|
|
|
2018-04-02 17:11:14 +09:00
|
|
|
app.post('/@:user/inbox', bodyParser.json({
|
|
|
|
type() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}), async (req, res) => {
|
2018-04-02 18:36:47 +09:00
|
|
|
let signature;
|
2018-04-01 15:58:49 +09:00
|
|
|
|
2018-04-02 00:36:36 +09:00
|
|
|
req.headers.authorization = 'Signature ' + req.headers.signature;
|
|
|
|
|
2018-04-01 15:58:49 +09:00
|
|
|
try {
|
2018-04-02 18:36:47 +09:00
|
|
|
signature = parseRequest(req);
|
2018-04-01 15:58:49 +09:00
|
|
|
} catch (exception) {
|
|
|
|
return res.sendStatus(401);
|
|
|
|
}
|
|
|
|
|
|
|
|
queue.create('http', {
|
2018-04-02 18:36:47 +09:00
|
|
|
type: 'processInbox',
|
|
|
|
inbox: req.body,
|
|
|
|
signature,
|
2018-04-01 15:58:49 +09:00
|
|
|
}).save();
|
|
|
|
|
2018-04-01 18:16:47 +09:00
|
|
|
return res.status(202).end();
|
2018-04-01 15:58:49 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
export default app;
|