1 Star 1 Fork 0

UyCode/server

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
render.js 779 Bytes
一键复制 编辑 原始数据 按行查看 历史
UyCode 提交于 2023-04-10 15:59 +08:00 . complete
let Renderer = require('engine/koa/renderer');
// (!) this.render does not assign this.body to the result
// that's because render can be used for different purposes, e.g to send emails
exports.init = function(app) {
app.use(async function(ctx, next) {
let renderer = new Renderer(ctx);
/**
* Render template
* Find the file:
* if locals.useAbsoluteTemplatePath => use templatePath
* else if templatePath starts with / => lookup in locals.basedir
* otherwise => lookup in ctx.templateDir (MW should set it)
* @param templatePath file to find (see the logic above)
* @param locals
* @returns {String}
*/
ctx.render = (templatePath, locals) => renderer.render(templatePath, locals);
await next();
});
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/UyCode/server.git
git@gitee.com:UyCode/server.git
UyCode
server
server
main

搜索帮助