Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1098,19 +1098,22 @@ async def index():
|
|
| 1098 |
if __name__ == "__main__":
|
| 1099 |
asyncio.run(initialize_tokens())
|
| 1100 |
app.run(host="0.0.0.0", port=CONFIG["SERVER"]["PORT"])
|
| 1101 |
-
|
| 1102 |
-
|
| 1103 |
-
|
| 1104 |
-
|
| 1105 |
-
|
| 1106 |
|
| 1107 |
-
#
|
| 1108 |
-
port =
|
| 1109 |
|
| 1110 |
-
#
|
| 1111 |
-
|
| 1112 |
-
|
| 1113 |
-
|
| 1114 |
-
|
| 1115 |
-
|
| 1116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1098 |
if __name__ == "__main__":
|
| 1099 |
asyncio.run(initialize_tokens())
|
| 1100 |
app.run(host="0.0.0.0", port=CONFIG["SERVER"]["PORT"])
|
| 1101 |
+
# 在现有app.py文件的最底部添加或修改这段代码
|
| 1102 |
+
if __name__ == "__main__":
|
| 1103 |
+
# 初始化令牌
|
| 1104 |
+
import asyncio
|
| 1105 |
+
asyncio.run(initialize_tokens())
|
| 1106 |
|
| 1107 |
+
# 获取端口,优先使用环境变量
|
| 1108 |
+
port = int(os.getenv("PORT", CONFIG["SERVER"]["PORT"]))
|
| 1109 |
|
| 1110 |
+
# 启动服务器
|
| 1111 |
+
from hypercorn.asyncio import serve
|
| 1112 |
+
from hypercorn.config import Config as HyperConfig
|
| 1113 |
+
|
| 1114 |
+
config = HyperConfig()
|
| 1115 |
+
config.bind = [f"0.0.0.0:{port}"]
|
| 1116 |
+
config.use_reloader = True
|
| 1117 |
+
|
| 1118 |
+
logger.info(f"服务器正在启动,端口:{port}", "Server")
|
| 1119 |
+
asyncio.run(serve(app, config))
|