Some bits for ReactJS-based client.
This commit is contained in:
parent
115d254baf
commit
4f52b571c9
27 changed files with 2326 additions and 202 deletions
24
lib/router-async.js
Normal file
24
lib/router-async.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
'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
|
||||
};
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue