better view loading practice
This commit is contained in:
parent
99184b9568
commit
239e90b01a
|
@ -2,6 +2,7 @@ const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const glob = require('glob');
|
const glob = require('glob');
|
||||||
|
|
||||||
|
router.use(require('./template'));
|
||||||
router.use(require('./cookie'));
|
router.use(require('./cookie'));
|
||||||
router.use(require('./session'));
|
router.use(require('./session'));
|
||||||
router.use(require('./session_back'));
|
router.use(require('./session_back'));
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
const express = require('express');
|
||||||
|
const router = new express.Router();
|
||||||
|
const Helpers = require('../helpers');
|
||||||
|
|
||||||
|
router.use((err, req, res, next) => {
|
||||||
|
if (res.template) return next();
|
||||||
|
res.template = async (file, data) => {
|
||||||
|
res.send(await Helpers.ViewLoader.load(file, {
|
||||||
|
...data,
|
||||||
|
current_route: req.originalUrl,
|
||||||
|
req,
|
||||||
|
res,
|
||||||
|
require
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
Loading…
Reference in New Issue