mirror of
https://github.com/blackboxprogramming/BlackRoad-Operating-System.git
synced 2026-03-17 07:57:19 -05:00
Allow configuring FastAPI port via environment
This commit is contained in:
@@ -284,7 +284,7 @@ async def serve_frontend():
|
|||||||
```bash
|
```bash
|
||||||
cd backend
|
cd backend
|
||||||
docker-compose up -d # Start PostgreSQL + Redis
|
docker-compose up -d # Start PostgreSQL + Redis
|
||||||
python run.py # Start FastAPI server on :8000
|
python run.py # Start FastAPI server (defaults to :8000 unless PORT is set)
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **Access UI:**
|
2. **Access UI:**
|
||||||
|
|||||||
@@ -56,9 +56,10 @@ docker run -d -p 6379:6379 redis:7-alpine
|
|||||||
|
|
||||||
### 4. Run Application
|
### 4. Run Application
|
||||||
```bash
|
```bash
|
||||||
python run.py
|
# PORT defaults to 8000 if not set
|
||||||
|
python run.py # respects the PORT env variable
|
||||||
# Or using uvicorn directly:
|
# Or using uvicorn directly:
|
||||||
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
|
uvicorn app.main:app --reload --host 0.0.0.0 --port ${PORT:-8000}
|
||||||
```
|
```
|
||||||
|
|
||||||
Access the API:
|
Access the API:
|
||||||
|
|||||||
@@ -23,4 +23,4 @@ COPY . .
|
|||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
# Run application
|
# Run application
|
||||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-8000}"]
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
# BlackRoad OS Backend Makefile
|
# BlackRoad OS Backend Makefile
|
||||||
|
|
||||||
|
PORT ?= 8000
|
||||||
|
|
||||||
.PHONY: help install dev run test clean docker-build docker-up docker-down
|
.PHONY: help install dev run test clean docker-build docker-up docker-down
|
||||||
|
|
||||||
help:
|
help:
|
||||||
@@ -23,7 +25,7 @@ dev:
|
|||||||
python run.py
|
python run.py
|
||||||
|
|
||||||
run:
|
run:
|
||||||
uvicorn app.main:app --host 0.0.0.0 --port 8000
|
uvicorn app.main:app --host 0.0.0.0 --port $(PORT)
|
||||||
|
|
||||||
test:
|
test:
|
||||||
pytest -v
|
pytest -v
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ nano .env
|
|||||||
docker run -d -p 5432:5432 -e POSTGRES_USER=blackroad -e POSTGRES_PASSWORD=password -e POSTGRES_DB=blackroad_db postgres:15-alpine
|
docker run -d -p 5432:5432 -e POSTGRES_USER=blackroad -e POSTGRES_PASSWORD=password -e POSTGRES_DB=blackroad_db postgres:15-alpine
|
||||||
docker run -d -p 6379:6379 redis:7-alpine
|
docker run -d -p 6379:6379 redis:7-alpine
|
||||||
|
|
||||||
# Run the application
|
# Run the application (PORT defaults to 8000 if unset)
|
||||||
python run.py
|
python run.py
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
"""Run the application"""
|
"""Run the application"""
|
||||||
|
import os
|
||||||
|
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
port = int(os.getenv("PORT", "8000"))
|
||||||
uvicorn.run(
|
uvicorn.run(
|
||||||
"app.main:app",
|
"app.main:app",
|
||||||
host="0.0.0.0",
|
host="0.0.0.0",
|
||||||
port=8000,
|
port=port,
|
||||||
reload=True,
|
reload=True,
|
||||||
log_level="info"
|
log_level="info"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user