Skip to main content

配置

🌐 Configuration

Strapi 项目的配置位于 /config 文件夹中:

🌐 The configuration of a Strapi project lives in the /config folder:

. # root of the project
├──── config
│ ├ api.js|ts
│ ├ admin.js|ts
│ ├ cron-tasks.js|ts
│ ├ database.js|ts
│ ├ features.js|ts
│ ├ middlewares.js|ts
│ ├ plugins.js|ts
│ └ server.js|ts
上面的区块是项目结构的摘录。你可以点击任何紫色的文件名以阅读相应的文档。访问 项目结构页面 查看完整版本。

基础配置

🌐 Base configurations

/config 文件夹中,你可以找到并定义以下基础配置:

🌐 From the /config folder, you can find and define the following base configurations: | 配置主题 | 文件路径 | 必需或可选 ||-----|----|----|| 数据库 | config/database | 必需 || 服务器 | config/server | 必需 || 管理面板 | config/admin | 必需 || 中间件 | config/middlewares | 必需 || API 调用 | config/api | 可选,用于定义一些响应的通用设置和其他与 REST 相关的参数。 |

特定功能的附加配置

🌐 Additional configuration for specific features

一些特定功能需要额外配置:

🌐 Some specific features require additional configuration:

功能位置必需或可选
插件config/plugins 文件中
  • 如果只使用带默认预设的内置插件,则可选。
  • 启用、配置或禁用插件时必需。
也可用于配置上传插件(处理媒体库功能)和 GraphQL。
TypeScript高效使用 TypeScript 所必需
API 令牌config/admin 文件中如果使用 API 令牌进行身份验证而不是使用 用户与权限插件 则为必需
生命周期函数/src/index 文件中可选地用于执行服务器生命周期中发生的各种操作。包括 registerbootstrapdestroy 函数。
Cron 作业
  • /config/server 文件中启用此功能
  • 在一个专用的可选 cron-tasks 文件中,可以用来声明作业
需要为服务器设置 CRON 作业。
环境变量在专门用于环境的文件和文件夹中(例如,config/env/production/server可选择用于定义不同的环境及其变量。
单点登录 (SSO) EnterpriseThis feature is available with an Enterprise plan. SSOThis feature is available with the SSO add-on.config/admin 文件中如果在你的项目中启用了 SSO 功能,则需要使用该功能。
功能标志config/features 文件中对于典型的、稳定的 Strapi 应用是可选的。
仅在需要启用未来标志时才需要。

指南

🌐 Guides

以下指南将帮助你解决与 Strapi 配置相关的特定用例:

🌐 The following guides will help you address specific use cases related to the Strapi configuration: