mailtrain/lib/router-async.js
2017-05-28 18:49:00 +02:00

24 lines
489 B
JavaScript

'use strict';
const express = require('express');
function safeHandler(handler) {
return function(req, res) {
handler(req, res).catch(error => res.status(500).send(error.message));
};
}
function create() {
const router = new express.Router();
router.getAsync = (path, asyncFn) => router.get(path, safeHandler(asyncFn));
router.postAsync = (path, asyncFn) => router.post(path, safeHandler(asyncFn));
return router;
}
module.exports = {
create
};