Support downloading configuration files from external URLs.
Browse files
main.py
CHANGED
@@ -22,14 +22,14 @@ async def lifespan(app: FastAPI):
|
|
22 |
timeout = httpx.Timeout(connect=15.0, read=10.0, write=30.0, pool=30.0)
|
23 |
app.state.client = httpx.AsyncClient(timeout=timeout)
|
24 |
import os
|
25 |
-
import
|
26 |
# 新增: 从环境变量获取配置URL并拉取配置
|
27 |
config_url = os.environ.get('CONFIG_URL')
|
28 |
if config_url:
|
29 |
try:
|
30 |
response = await app.state.client.get(config_url)
|
31 |
response.raise_for_status()
|
32 |
-
config_data =
|
33 |
# 更新配置
|
34 |
global config, api_keys_db, api_list
|
35 |
config, api_keys_db, api_list = update_config(config_data)
|
|
|
22 |
timeout = httpx.Timeout(connect=15.0, read=10.0, write=30.0, pool=30.0)
|
23 |
app.state.client = httpx.AsyncClient(timeout=timeout)
|
24 |
import os
|
25 |
+
import yaml
|
26 |
# 新增: 从环境变量获取配置URL并拉取配置
|
27 |
config_url = os.environ.get('CONFIG_URL')
|
28 |
if config_url:
|
29 |
try:
|
30 |
response = await app.state.client.get(config_url)
|
31 |
response.raise_for_status()
|
32 |
+
config_data = yaml.safe_load(response.text)
|
33 |
# 更新配置
|
34 |
global config, api_keys_db, api_list
|
35 |
config, api_keys_db, api_list = update_config(config_data)
|