Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

eggjs 模板渲染nunjucks 部署到docker后 访问路由 报500错误

使用的eggjs文档提供的demo,并且成功部署到了docker,服务接口可以正常访问,但是模板渲染接口报错500

demo

controll.js

`

'use strict';
const Controller = require('egg').Controller;
class Index extends Controller {
  async index() {
    const ctx = this.ctx;
    const page = ctx.query.page || 1;
    const newsList = await ctx.service.index.list(page);
    await ctx.render('index.tpl', { list: newsList });
  }
}
module.exports = Home;

`

default.config.js

`

exports.view = {
defaultViewEngine: 'nunjucks',
mapping: {
  '.tpl': 'nunjucks'
},

};
`

router

`

router.get('/', controller.index.index);

`

view下是index.tpl模板

然后本地访问是没问题的,但是部署到docker后就只能访问controll中的服务接口,模板路由就会报错500
tip:部署到docker后只运行了egg-script start
是否是因为本地启动已经进行了模板编译?也就是把.tpl的模板编译成了html到内存中,部署到docker后 是不是要接入webpack把tpl打包到public中?才能访问?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

是的自己经过了测试 线上需要提前构建 tpl是模板文件必须要编译成html或者直接在constroll中映射成html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...