跳转到内容

配置

rCommerce 通过 TOML 文件配置。每个选项都有合理的默认值。

按优先级从高到低:

  1. RCOMMERCE_CONFIG 环境变量指定的路径
  2. ./config/default.toml
  3. ./config/production.toml
  4. /etc/rcommerce/config.toml
[server]
host = "0.0.0.0" # 绑定地址
port = 8080 # 监听端口
worker_threads = 0 # 0 = 使用 CPU 核数
[server.cors]
enabled = true
allowed_origins = ["*"]
allowed_methods = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"]
allowed_headers = ["Content-Type", "Authorization"]
[database]
db_type = "Postgres"
host = "localhost"
port = 5432
database = "rcommerce"
username = "rcommerce"
password = "password"
pool_size = 20
[cache]
cache_type = "Memory" # 或 "Redis"
max_size_mb = 100
redis_url = "redis://localhost:6379"
[security]
api_key_prefix_length = 40
api_key_secret_length = 40
[security.jwt]
secret = "change-this-in-production"
expiry_hours = 24
[payment]
default_gateway = "airwallex" # 或 "stripe" / "mock"
test_mode = true
[payment.stripe]
enabled = true
secret_key = "sk_test_..."
publishable_key = "pk_test_..."
[payment.airwallex]
enabled = false
client_id = ""
api_key = ""
webhook_secret = ""
demo = true
[orders]
# 未支付(待付款)订单经过这么多分钟后自动取消,释放库存预留。
# 不设置 = 清扫器停用。
auto_cancel_pending_minutes = 120
[accounting]
store_code = "SHOP" # 账单/订单引用中的短代码
store_name = "My Shop" # 会计导出中的店铺名
site_url = "https://shop.example.com" # 嵌入支付服务商元数据

这些值作用于 会计导出参考中的导出和 结算同步端点。

[shipping]
default_provider = "weight_based"
[shipping.weight_based]
# 分区运费在代码中配置
# 详见物流指南
[notifications]
enabled = true
[notifications.email]
# 方式 1:Postmark(推荐——无需维护 SMTP 服务器)
postmark_token = "your-server-token"
postmark_stream = "outbound" # 可选,默认 "outbound"
from_email = "[email protected]"
from_name = "Your Store"
# 方式 2:SMTP
smtp_host = "smtp.example.com"
smtp_port = 465 # 465 = 隐式 TLS (SMTPS),587 = STARTTLS
smtp_user = "[email protected]"
smtp_pass = "password"
smtp_tls = true

Postmark 和 SMTP 二选一:设置 postmark_token 即通过 Postmark API 发送,或设置 smtp_* 通过 SMTP 发送。

[features]
debug_api = true # 启用调试端点
metrics = true # Prometheus 指标
health_check = true # /health 端点
[tls]
enabled = false
cert_path = "/path/to/cert.pem"
key_path = "/path/to/key.pem"