Skip to content

Commit dec369a

Browse files
committed
feat: add command-line argument for backend server port configuration
1 parent df6388a commit dec369a

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Once everything is set up:
126126

127127
```bash
128128
cd backend
129-
uv run main.py
129+
uv run main.py --port 8000
130130
```
131131

132132
The backend server will start on http://localhost:8000. You can verify it's running by visiting http://localhost:8000/api/v1/health in your browser.

backend/main.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from fastapi import FastAPI
22
from fastapi.middleware.cors import CORSMiddleware
33
from fastapi.staticfiles import StaticFiles
4+
import argparse
45
import os
56
import logging
67

@@ -52,7 +53,18 @@ def health_check():
5253
return {"status": "ok"}
5354

5455

55-
# This allows the file to be run directly with `python backend/main.py`
5656
if __name__ == "__main__":
5757
import uvicorn
58-
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
58+
59+
# Set up command-line argument parsing
60+
parser = argparse.ArgumentParser(
61+
description="Run the Visionary Lab backend server")
62+
parser.add_argument(
63+
"--port", type=int, help="Port to run the server on (default: 8000 or PORT env var)")
64+
args = parser.parse_args()
65+
66+
# Use command-line port if specified, otherwise use environment PORT variable,
67+
# and finally fall back to default 8000
68+
port = args.port if args.port is not None else int(
69+
os.environ.get("PORT", 80))
70+
uvicorn.run("main:app", host="0.0.0.0", port=port, reload=True)

0 commit comments

Comments
 (0)