-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
49 lines (35 loc) · 1.18 KB
/
run.py
File metadata and controls
49 lines (35 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""PosterPilot entry point.
Works for local development, PyInstaller EXE, and Docker.
"""
import os
import sys
import webbrowser
import threading
import uvicorn
from app.config import Config
def open_browser(host: str, port: int) -> None:
"""Open the browser after a short delay to let the server start."""
import time
time.sleep(1.5)
url = f"http://{'127.0.0.1' if host == '0.0.0.0' else host}:{port}"
webbrowser.open(url)
def main() -> None:
config = Config.load()
host = config.app.host
port = config.app.port
# Open browser on Windows EXE or local dev (not Docker)
in_docker = os.environ.get("POSTERPILOT_DOCKER", "").lower() in ("1", "true")
if config.app.open_browser and not in_docker:
threading.Thread(target=open_browser, args=(host, port), daemon=True).start()
print(f"Starting PosterPilot on http://{host}:{port}")
print("Press Ctrl+C to stop.\n")
uvicorn.run(
"app.main:create_app",
host=host,
port=port,
factory=True,
log_level=config.app.log_level.lower(),
reload=not getattr(sys, "frozen", False), # Auto-reload in dev only
)
if __name__ == "__main__":
main()