add server to monorepo.

This commit is contained in:
a.bouhuolia
2023-02-03 11:57:50 +02:00
parent 28e309981b
commit 80b97b5fdc
1303 changed files with 137049 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
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;