init: chongming 项目模板(init.py 初始化骨架 + 内置插件最小示例)
This commit is contained in:
+155
@@ -0,0 +1,155 @@
|
||||
[default]
|
||||
app.debug = false
|
||||
app.description = "{{app_name}} — chongming 网关项目"
|
||||
app.name = "{{app_name}}"
|
||||
app.version = "0.1.0"
|
||||
env = "development"
|
||||
prefix = "/api/v1"
|
||||
upload_path = "uploads"
|
||||
|
||||
[zenoh]
|
||||
json5_path = "./config/zenoh_config.json5"
|
||||
|
||||
[cache]
|
||||
# 单机默认 sqlite(本机共享);多实例部署改 "redis"(或共享卷 sqlite),各实例指向同一后端
|
||||
backend = "sqlite"
|
||||
path = "./cache_data/cache.db"
|
||||
# 副本数/运行时配置的取值来源:
|
||||
# "toml"(默认)= 以文件为准(启动用 config/workers/<type>/config.toml 覆盖写入缓存)
|
||||
# "cache" = 以缓存为单一事实来源(管理接口改动跨重启保持)
|
||||
launch_worker_count = "toml"
|
||||
|
||||
# redis 后端专用(backend = "redis" 时生效)
|
||||
redis_host = "127.0.0.1"
|
||||
redis_port = 6379
|
||||
redis_db = 0
|
||||
redis_password = ""
|
||||
redis_prefix = "chongming:"
|
||||
|
||||
[security]
|
||||
# 打包装备(uv run build)会自动注入随机密钥;生产环境请改用环境变量或自行替换
|
||||
algorithm = "HS256"
|
||||
secret_key = "your-secret-key-change-in-production"
|
||||
|
||||
[development]
|
||||
debug = true
|
||||
env = "development"
|
||||
|
||||
[development.server]
|
||||
# 三个启动入口(serve / granian / gunicorn)共用这些参数
|
||||
access_log = false
|
||||
host = "0.0.0.0"
|
||||
port = 8000
|
||||
reload = true
|
||||
|
||||
[development.logging]
|
||||
file = "logs"
|
||||
format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
||||
level = "DEBUG"
|
||||
# access 日志采样率:0.1 = 只记录 10% 的成功请求(错误 >=400 始终全量)
|
||||
access_sample_rate = 0.1
|
||||
|
||||
[development.cors]
|
||||
allow_credentials = true
|
||||
allow_headers = ["*"]
|
||||
allow_methods = ["*"]
|
||||
# allow_credentials=true 时 allow_origins 不能为 ["*"],需显式列出来源
|
||||
allow_origins = [
|
||||
"http://localhost:5173",
|
||||
"http://127.0.0.1:5173",
|
||||
"http://localhost:5174",
|
||||
"http://127.0.0.1:5174",
|
||||
]
|
||||
|
||||
[development.mqtt]
|
||||
enabled = true
|
||||
host = "127.0.0.1"
|
||||
port = 1883
|
||||
# true(默认)= 网关自带内嵌 amqtt Broker(开箱即用);
|
||||
# false = 连接外部 Broker,host/port 改为对方地址
|
||||
use_embedded_broker = true
|
||||
# Broker 认证(可选,默认匿名;密码明文存放,生产建议外部 Broker + 环境变量注入)
|
||||
# username = "chongming"
|
||||
# password = "change-me"
|
||||
|
||||
[development.mqtt.broker]
|
||||
# amqtt Broker 可选配置,默认允许匿名连接
|
||||
|
||||
# 旧式全局插件注册文件(仅作兜底兼容;新插件请在 config/workers/<type>/config.toml 各自声明)
|
||||
[plugins_worker]
|
||||
config_path = "./config/workers/config.toml"
|
||||
|
||||
[pyinstaller_build_import]
|
||||
# 打包收集清单(PyInstaller --hidden-import / Nuitka --include-module),`uv run build` 的
|
||||
# pack 步骤使用。网关本体依赖随 chongming-gateway 包发布、静态分析可跟到;这里保留:
|
||||
# - 动态导入、静态分析看不到的(granian 内部子模块、amqtt 插件、sqlite_vfs 等)
|
||||
# - public 骨架自身(server / utils)与服务器可选实现(uvloop 等)
|
||||
# 内置插件专属依赖(网关本体不 import 的第三方包)写根目录 plugins_deps.toml,按插件分节声明。
|
||||
base = [
|
||||
"utils",
|
||||
"utils.launch",
|
||||
"utils.config",
|
||||
"server",
|
||||
"module_bank",
|
||||
"granian",
|
||||
"granian._compat",
|
||||
"granian._futures",
|
||||
"granian._granian",
|
||||
"granian._imports",
|
||||
"granian._internal",
|
||||
"granian._loops",
|
||||
"granian._signals",
|
||||
"granian._types",
|
||||
"granian.asgi",
|
||||
"granian.constants",
|
||||
"granian.errors",
|
||||
"granian.http",
|
||||
"granian.log",
|
||||
"granian.net",
|
||||
"granian.rsgi",
|
||||
"granian.server",
|
||||
"granian.server.common",
|
||||
"granian.server.mp",
|
||||
"granian.server.mt",
|
||||
"granian.wsgi",
|
||||
"httptools",
|
||||
"uvicorn",
|
||||
"sqlite_vfs",
|
||||
"sqlite_vfs.core",
|
||||
"sqlite_vfs.contrib",
|
||||
"sqlite_vfs.contrib.fastapi_static",
|
||||
"amqtt",
|
||||
# amqtt 内嵌 Broker 的插件经 entry points 动态加载,静态分析看不到
|
||||
"amqtt.plugins.authentication",
|
||||
"amqtt.plugins.logging_amqtt",
|
||||
"amqtt.plugins.sys.broker",
|
||||
"amqtt.plugins.topic_checking",
|
||||
# 数据库 / 缓存驱动:SQLAlchemy 与 chongming-cache 按配置动态加载,必须显式声明
|
||||
"aiosqlite", # SQLite 异步驱动(网关内置 auth 库用)
|
||||
"asyncpg", # PostgreSQL 驱动(插件配 database.url 时用)
|
||||
"sqlmodel",
|
||||
"chongming_cache.backends",
|
||||
"chongming_cache.backends.sqlite_", # cache backend = "sqlite" 时使用
|
||||
"chongming_worker.contracts",
|
||||
"chongming_worker.route_config",
|
||||
"chongming_worker.routes_publisher",
|
||||
"python_multipart", # multipart 上传端点
|
||||
"orjson",
|
||||
"aiofiles",
|
||||
]
|
||||
linux = [
|
||||
"uvloop",
|
||||
]
|
||||
windows = []
|
||||
|
||||
[production.module_system]
|
||||
# 构建用(uv run build 的 mbank 步骤读这里):把插件源码打进 resources/plugins.mbank,
|
||||
# 交付产物运行时经模块银行加载插件(网关本体是普通依赖包,不进 .mbank)
|
||||
path = [
|
||||
[
|
||||
"resources/plugins.mbank",
|
||||
"src/plugins",
|
||||
"plugins",
|
||||
],
|
||||
]
|
||||
type = "module-bank"
|
||||
Reference in New Issue
Block a user