diff --git a/middleware/index.js b/middleware/index.js index 5238f29..547dcc7 100644 --- a/middleware/index.js +++ b/middleware/index.js @@ -2,6 +2,7 @@ const express = require('express'); const router = express.Router(); const glob = require('glob'); +router.use(require('./template')); router.use(require('./cookie')); router.use(require('./session')); router.use(require('./session_back')); diff --git a/middleware/template.js b/middleware/template.js new file mode 100644 index 0000000..5865962 --- /dev/null +++ b/middleware/template.js @@ -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; \ No newline at end of file