模板作者: @Cigaret(cigaret)

💬 修改意见

  • 甲方提出的修改意见
  • 如果没有甲方,就自己做自己的甲方

📄 修改规划

  • 对修改意见的解读
  • 将修改意见的解读映射到文章结构和内容

✅ 修改内容

  • 实际修改的结构或内容

🛒 版本总结

  • 总结本次迭代的经验和成果等

🔖 参考资料

1. strapi 来作为静态资源服务器

  1. strapi.router.get(
  2. '/(.*)',
  3. koaStatic(staticDir, {
  4. maxage: maxAge,
  5. defer: true,
  6. })
  7. );

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’)) // /fe-dist ); } }; };

  1. - `touch <strapi-app>/config/middleware.js`<br />
  2. ```javascript
  3. module.exports = {
  4. load: {
  5. before: ['responseTime', 'logger', 'cors', 'responses', 'gzip'],
  6. order: [
  7. "Define the middlewares' load order by putting their name in this array is the right order",
  8. 'serve-fe-dist',
  9. ],
  10. after: ['parser', 'router'],
  11. },
  12. settings: {
  13. 'serve-fe-dist': {
  14. enabled: true,
  15. },
  16. },
  17. };
  • 方案2:通过配置修改 strapi 默认的 piblicPath
    • touch /config/middleware.js
    • ⚠️不过这种方式有问题:会导致上传文件的路径变为: publicPath/uploads,导致文件会因为构建前端而被删除,因此还是回退到上面的方案1
      1. module.exports = {
      2. settings: {
      3. public: {
      4. path: './fe-dist' // 即 <strapi-app>/fe-dist
      5. }
      6. },
      7. };

2. ctx.render is not function

  1. yarn add strapi-hook-ejs
  2. #<strapi-app>/config/hook.js
  3. module.exports = {
  4. settings: {
  5. ejs: {
  6. enabled: true,
  7. "viewExt": "ejs",
  8. "partial": true,
  9. "cache": false,
  10. "debug": false,
  11. "layout": false
  12. },
  13. },
  14. }