feat: Allow setting port as PORT env var
Some checks failed
Create and publish a Docker image / build-and-push-image (push) Has been cancelled

This seems important for render hosting, as described in
https://render.com/docs/web-services#port-binding.
This commit is contained in:
Marty Oehme 2025-07-22 06:06:15 +02:00
parent 2da0b90b1b
commit 4ef2ce14d6
Signed by: Marty
GPG key ID: 4E535BC19C61886E
2 changed files with 14 additions and 1 deletions

View file

@ -8,6 +8,7 @@ from fastapi.staticfiles import StaticFiles
from fastapi_utils.tasks import repeat_every
from prophet import view
from prophet.config import AppConfig
from prophet.domain.improvement import Improvement
from prophet.domain.improvement_repo import IImprovementRepo
from prophet.domain.original import Original
@ -135,7 +136,9 @@ async def fetch_update(debug_print: bool = True):
def start() -> None:
from uvicorn import run
run("prophet.app:app", reload=True, host="0.0.0.0")
config = AppConfig.from_env()
run("prophet.app:app", reload=True, host="0.0.0.0", port=config.PORT)
if __name__ == "__main__":

View file

@ -8,6 +8,16 @@ from dotenv import load_dotenv
_ = load_dotenv()
@dataclass
class AppConfig:
PORT: int
@classmethod
def from_env(cls) -> "AppConfig":
PORT = os.getenv("PORT", "8000")
return cls(PORT=int(PORT))
@dataclass
class AiConfig:
API_KEY: str