Spaces:
Running
Running
yangzhitao
commited on
Commit
·
bd30e41
1
Parent(s):
0b237ab
feat: update FastAPI configuration to use settings for host and port
Browse files- Refactored the FastAPI server initialization to retrieve host and port from the new settings in envs.py.
- Added BACKEND_HOST and BACKEND_PORT fields to the Settings class for better configuration management.
- app.py +3 -1
- src/envs.py +3 -0
app.py
CHANGED
|
@@ -495,7 +495,9 @@ if __name__ == "__main__":
|
|
| 495 |
# Backend server - 在单独的线程中运行
|
| 496 |
app = create_app()
|
| 497 |
|
| 498 |
-
def run_fastapi(
|
|
|
|
|
|
|
| 499 |
print(f"Starting FastAPI server on http://{host}:{port}")
|
| 500 |
uvicorn.run(
|
| 501 |
app,
|
|
|
|
| 495 |
# Backend server - 在单独的线程中运行
|
| 496 |
app = create_app()
|
| 497 |
|
| 498 |
+
def run_fastapi():
|
| 499 |
+
host = settings.BACKEND_HOST
|
| 500 |
+
port = settings.BACKEND_PORT
|
| 501 |
print(f"Starting FastAPI server on http://{host}:{port}")
|
| 502 |
uvicorn.run(
|
| 503 |
app,
|
src/envs.py
CHANGED
|
@@ -22,6 +22,9 @@ class Settings(BaseSettings):
|
|
| 22 |
Field("y-playground"),
|
| 23 |
]
|
| 24 |
|
|
|
|
|
|
|
|
|
|
| 25 |
@computed_field
|
| 26 |
@cached_property
|
| 27 |
def REPO_ID(self) -> str:
|
|
|
|
| 22 |
Field("y-playground"),
|
| 23 |
]
|
| 24 |
|
| 25 |
+
BACKEND_HOST: Annotated[str, Field("127.0.0.1", description="Backend host")]
|
| 26 |
+
BACKEND_PORT: Annotated[int, Field(8000, description="Backend port")]
|
| 27 |
+
|
| 28 |
@computed_field
|
| 29 |
@cached_property
|
| 30 |
def REPO_ID(self) -> str:
|