fix(docs): fix config toml
This commit is contained in:
@@ -400,17 +400,16 @@ cargo run -- -c config/local.toml
|
||||
|
||||
**重要**:本项目不支持 .env 文件。开发环境请使用 `config/` 目录下的 toml 配置文件。
|
||||
|
||||
复制并修改 MySQL 配置文件:
|
||||
编辑 MySQL 配置文件:
|
||||
|
||||
```bash
|
||||
# 复制 MySQL 配置模板
|
||||
cp config/development.mysql.toml config/local.toml
|
||||
# 编辑开发环境配置文件
|
||||
nano config/development.toml
|
||||
|
||||
# 编辑 config/local.toml,修改数据库连接信息
|
||||
nano config/local.toml
|
||||
# 设置 database.type = "mysql" 并修改连接信息
|
||||
|
||||
# 运行
|
||||
cargo run -- -c config/local.toml
|
||||
cargo run
|
||||
```
|
||||
|
||||
或使用环境变量(适用于 Docker/Kubernetes):
|
||||
|
||||
@@ -92,22 +92,15 @@ cargo run
|
||||
|
||||
#### 方式二:使用 MySQL/PostgreSQL
|
||||
|
||||
**步骤 1**:复制对应的配置文件
|
||||
**步骤 1**:修改配置文件
|
||||
|
||||
```bash
|
||||
# 使用 MySQL
|
||||
cp config/development.mysql.toml config/local.toml
|
||||
|
||||
# 或使用 PostgreSQL
|
||||
cp config/development.postgresql.toml config/local.toml
|
||||
```
|
||||
|
||||
**步骤 2**:修改配置文件
|
||||
|
||||
编辑 `config/local.toml`,修改数据库连接信息:
|
||||
编辑 `config/development.toml`,修改数据库类型和连接信息:
|
||||
|
||||
```toml
|
||||
[database]
|
||||
# 修改数据库类型:mysql, postgresql 或 sqlite
|
||||
type = "mysql" # 或 "postgresql"
|
||||
|
||||
# MySQL 配置
|
||||
host = "localhost"
|
||||
port = 3306
|
||||
@@ -116,6 +109,7 @@ password = "your-password"
|
||||
database = "web_template_dev"
|
||||
|
||||
# 或 PostgreSQL 配置
|
||||
# type = "postgresql"
|
||||
# host = "localhost"
|
||||
# port = 5432
|
||||
# user = "postgres"
|
||||
@@ -123,11 +117,10 @@ database = "web_template_dev"
|
||||
# database = "web_template_dev"
|
||||
```
|
||||
|
||||
**步骤 3**:运行项目
|
||||
**步骤 2**:运行项目
|
||||
|
||||
```bash
|
||||
# 使用指定配置文件运行
|
||||
cargo run -- -c config/local.toml
|
||||
cargo run
|
||||
```
|
||||
|
||||
#### 方式三:通过环境变量覆盖(适用于 Docker/Kubernetes)
|
||||
@@ -171,11 +164,16 @@ cargo run
|
||||
|
||||
**选项 1**:修改配置文件
|
||||
|
||||
```bash
|
||||
# 复制 MySQL 配置模板
|
||||
cp config/development.mysql.toml config/local.toml
|
||||
编辑 `config/development.toml`,设置数据库类型为 `mysql` 并修改连接信息:
|
||||
|
||||
# 编辑 config/local.toml,修改数据库连接信息
|
||||
```toml
|
||||
[database]
|
||||
type = "mysql"
|
||||
host = "localhost"
|
||||
port = 3306
|
||||
user = "root"
|
||||
password = "your-password"
|
||||
database = "web_template_dev"
|
||||
```
|
||||
|
||||
**选项 2**:使用环境变量
|
||||
@@ -198,7 +196,21 @@ cargo run
|
||||
|
||||
**适用场景**:需要高级数据库功能的应用
|
||||
|
||||
**配置方法**:与 MySQL 类似,使用 `config/development.postgresql.toml` 或环境变量
|
||||
**配置方法**:
|
||||
|
||||
编辑 `config/development.toml`,设置数据库类型为 `postgresql` 并修改连接信息:
|
||||
|
||||
```toml
|
||||
[database]
|
||||
type = "postgresql"
|
||||
host = "localhost"
|
||||
port = 5432
|
||||
user = "postgres"
|
||||
password = "your-password"
|
||||
database = "web_template_dev"
|
||||
```
|
||||
|
||||
或使用环境变量(格式与 MySQL 相同)。
|
||||
|
||||
### 认证配置
|
||||
|
||||
@@ -243,7 +255,8 @@ cargo run
|
||||
|
||||
**使用指定配置文件**:
|
||||
```bash
|
||||
cargo run -- -c config/development.mysql.toml
|
||||
# 修改 config/development.toml 后运行
|
||||
cargo run
|
||||
```
|
||||
|
||||
**使用环境变量**:
|
||||
|
||||
@@ -99,10 +99,8 @@ web-rust-template/
|
||||
│
|
||||
├── config/ # 配置文件目录
|
||||
│ ├── default.toml # 默认配置
|
||||
│ ├── development.sqlite.toml # SQLite 开发环境配置
|
||||
│ ├── development.mysql.toml # MySQL 开发环境配置
|
||||
│ ├── development.postgresql.toml # PostgreSQL 开发环境配置
|
||||
│ └── production.toml # 生产环境配置
|
||||
│ ├── development.toml # 开发环境配置(支持 MySQL/PostgreSQL/SQLite)
|
||||
│ └── production.toml # 生产环境配置
|
||||
│
|
||||
├── sql/ # SQL 脚本
|
||||
│ └── init.sql # 数据库初始化脚本
|
||||
|
||||
Reference in New Issue
Block a user