模板作者: @Cigaret(cigaret)
💬 修改意见
- 甲方提出的修改意见
- 如果没有甲方,就自己做自己的甲方
📄 修改规划
- 对修改意见的解读
- 将修改意见的解读映射到文章结构和内容
✅ 修改内容
- 实际修改的结构或内容
🛒 版本总结
- 总结本次迭代的经验和成果等
🔖 参考资料
1. strapi 来作为静态资源服务器
strapi.router.get('/(.*)',koaStatic(staticDir, {maxage: maxAge,defer: true,}));
- 方案1:通过middleware,来实现访问
定义在router.json之外的路由时,会走上面的 koaStatic 逻辑,即自定义首页touch <strapi-app>/middlewares/serve-fe-dist/index.js
```javascript /*- You will find information here:
const koaStatic = require(‘koa-static’); const path = require(‘path’);
module.exports = strapi => {
return {
// eslint-disable-next-line no-unused-vars
initialize: function(cb) {
// https://github.com/strapi/strapi/blob/master/packages/strapi/lib/middlewares/public/index.js#L73
strapi.router.get(
‘/*’,
koaStatic(path.resolve(‘./fe-dist’)) //
- `touch <strapi-app>/config/middleware.js`<br />```javascriptmodule.exports = {load: {before: ['responseTime', 'logger', 'cors', 'responses', 'gzip'],order: ["Define the middlewares' load order by putting their name in this array is the right order",'serve-fe-dist',],after: ['parser', 'router'],},settings: {'serve-fe-dist': {enabled: true,},},};
- 方案2:通过配置修改 strapi 默认的 piblicPath
- touch
/config/middleware.js - ⚠️不过这种方式有问题:会导致上传文件的路径变为:
publicPath/uploads,导致文件会因为构建前端而被删除,因此还是回退到上面的方案1module.exports = {settings: {public: {path: './fe-dist' // 即 <strapi-app>/fe-dist}},};
- touch
2. ctx.render is not function
yarn add strapi-hook-ejs#<strapi-app>/config/hook.jsmodule.exports = {settings: {ejs: {enabled: true,"viewExt": "ejs","partial": true,"cache": false,"debug": false,"layout": false},},}
