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
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:
parent
2da0b90b1b
commit
4ef2ce14d6
2 changed files with 14 additions and 1 deletions
|
|
@ -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__":
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue