mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-13 11:20:31 +00:00
24 lines
648 B
TypeScript
24 lines
648 B
TypeScript
import { Request, Response } from 'express';
|
|
|
|
const asyncRender = (app) => (path: string, attributes = {}) =>
|
|
new Promise((resolve, reject) => {
|
|
app.render(path, attributes, (error, data) => {
|
|
if (error) { reject(error); }
|
|
|
|
resolve(data);
|
|
});
|
|
});
|
|
|
|
/**
|
|
* Injects `asyncRender` method to response object.
|
|
* @param {Request} req Express req Object
|
|
* @param {Response} res Express res Object
|
|
* @param {NextFunction} next Express next Function
|
|
*/
|
|
const asyncRenderMiddleware = (req: Request, res: Response, next: Function) => {
|
|
res.asyncRender = asyncRender(req.app);
|
|
next();
|
|
};
|
|
|
|
export default asyncRenderMiddleware;
|