Strapi 5 填坑指南

50 阅读1分钟
  1. 在windows 使用pnpm包管理器运行时需要注意路径长度问题:
pnpm config set enable-long-paths true
  1. 在windows 媒体库上传jpg,jpeg文件是会报错,但是图片实际已上传,解决方法有些繁琐,在linux上正常
  2. 如果需要使用OSS,COS等保存文件,需要安装对应的 provider,例如 strapi-provider-upload-tencent-cloud-storage,同时还需要在 config/middlewares.ts 中设置strapi::security,将COS的域名加入到配置中,示例如下:
export default [
  'strapi::logger',
  'strapi::errors',
  'strapi::cors',
  'strapi::poweredBy',
  'strapi::query',
  'strapi::body',
  'strapi::session',
  'strapi::favicon',
  'strapi::public',
  {
    name: "strapi::security",
    config: {
      contentSecurityPolicy: {
        useDefaults: true,
        directives: {
          "connect-src": ["'self'", "https:"],
          "img-src": [
            "'self'",
            "data:",
            "blob:",
            "market-assets.strapi.io",
            "cos.sanyuangongxue.com",  // 新增的COS域名
            "ai-xuexi-1253431726.cos.ap-shanghai.myqcloud.com", // 新增的COS域名
          ],
          "media-src": [
            "'self'",
            "data:",
            "blob:",
            "market-assets.strapi.io",
            "cos.sanyuangongxue.com",  // 新增的COS域名
            "ai-xuexi-1253431726.cos.ap-shanghai.myqcloud.com", // 新增的COS域名
          ],
          upgradeInsecureRequests: null,
        },
      },
    },
  },
];

  1. 如果要将页面显示为简体中文,需要在 src/admin/app.tsx 中增加区域选项 "zh-Hans",然后在 profile 页面会出现简体中文的选项,保存后即可
  2. 切换为简体中文后,有些界面元素依然显示为英文,可以在 src/admin/app.tsx 中的 translations 中增加简体中文的翻译,具体的key值可以查看对应源码文件,安装的插件也参考此规律,比如content-type-builder虽然默认安装时已包含在Strapi中,但是其实是作为插件plugin运行的,而且目前此插件的简体中文翻译中包含了大量的繁体中文,可以在这里自行覆盖为简体中文
  3. 在服务端部署时,如果使用nginx作为反向代理时通过域名访问时,需要注意hostname的配置,否则会出现Blocked request. This host ("www.xxx.com") is not allowed. 的错误