yym68686 commited on
Commit
467f256
·
1 Parent(s): 8e8b08a

🐛 Bug: Fix the bug where Vercel fails to start successfully.

Browse files
Files changed (2) hide show
  1. main.py +2 -1
  2. utils.py +20 -1
main.py CHANGED
@@ -582,8 +582,9 @@ class ClientManager:
582
 
583
  @app.middleware("http")
584
  async def ensure_config(request: Request, call_next):
 
585
  if app and not hasattr(app.state, 'config'):
586
- logger.warning("Config not found, attempting to reload")
587
  app.state.config, app.state.api_keys_db, app.state.api_list = await load_config(app)
588
 
589
  for item in app.state.api_keys_db:
 
582
 
583
  @app.middleware("http")
584
  async def ensure_config(request: Request, call_next):
585
+
586
  if app and not hasattr(app.state, 'config'):
587
+ # logger.warning("Config not found, attempting to reload")
588
  app.state.config, app.state.api_keys_db, app.state.api_list = await load_config(app)
589
 
590
  for item in app.state.api_keys_db:
utils.py CHANGED
@@ -166,7 +166,26 @@ async def load_config(app=None):
166
  config_url = os.environ.get('CONFIG_URL')
167
  if config_url:
168
  try:
169
- client = app.state.client_manager.get_client(100)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  response = await client.get(config_url)
171
  # logger.info(f"Fetching config from {response.text}")
172
  response.raise_for_status()
 
166
  config_url = os.environ.get('CONFIG_URL')
167
  if config_url:
168
  try:
169
+ default_config = {
170
+ "headers": {
171
+ "User-Agent": "curl/7.68.0",
172
+ "Accept": "*/*",
173
+ },
174
+ "http2": True,
175
+ "verify": True,
176
+ "follow_redirects": True
177
+ }
178
+ # 初始化客户端管理器
179
+ timeout = httpx.Timeout(
180
+ connect=15.0,
181
+ read=100,
182
+ write=30.0,
183
+ pool=200
184
+ )
185
+ client = httpx.AsyncClient(
186
+ timeout=timeout,
187
+ **default_config
188
+ )
189
  response = await client.get(config_url)
190
  # logger.info(f"Fetching config from {response.text}")
191
  response.raise_for_status()