fix variable in env

This commit is contained in:
2026-04-28 10:18:44 +07:00
parent f6c5dce452
commit 7cace210d6
7 changed files with 79 additions and 16 deletions
+14
View File
@@ -0,0 +1,14 @@
DASHBOARD_PORT=8008
MEDIAMTX_API_URL=http://127.0.0.1:9997
MEDIAMTX_WEBRTC_URL=http://127.0.0.1:8889
RECORDINGS_DIR=/recordings
MEDIAMTX_API_USER=
MEDIAMTX_API_PASS=
CORS_ORIGINS=http://localhost:5173
VITE_DEV_BACKEND_URL=http://localhost:8008
VITE_API_BASE_URL=/api
VITE_MEDIAMTX_WEBRTC_URL=
+5 -1
View File
@@ -24,8 +24,12 @@ dist-ssr
*.sw? *.sw?
api/.venv/ api/.venv/
api/__pycache__
api/__init__.py
api/app/__pycache__/ api/app/__pycache__/
api/data api/data
.env
# recordings # recordings
mediamtx/recordings mediamtx/recordings
+19 -14
View File
@@ -65,11 +65,11 @@ authInternalUsers:
- action: api - action: api
``` ```
Sau đó trên máy chạy dashboard backend: Sau đó set trong file `.env` của dashboard backend:
```bash ```
export MEDIAMTX_API_USER="dashboard" MEDIAMTX_API_USER=dashboard
export MEDIAMTX_API_PASS="dashboard_password" MEDIAMTX_API_PASS=dashboard_password
``` ```
Trong `paths`, bạn có thể để dashboard tự thêm path bằng API (Settings → Add Camera). Trong `paths`, bạn có thể để dashboard tự thêm path bằng API (Settings → Add Camera).
@@ -128,7 +128,15 @@ pip install -r api/requirements.txt
### 3.2 Cấu hình ### 3.2 Cấu hình
Chạy backend lần đầu sẽ tự tạo `api/data/config.json`. Tạo file `.env`:
```bash
cp .env.example .env
```
Backend sẽ tự load `.env` khi start.
Chạy backend lần đầu sẽ tự tạo `api/data/config.json` (lưu danh sách camera + schedule).
Bạn có thể chỉnh: Bạn có thể chỉnh:
@@ -156,18 +164,16 @@ export MEDIAMTX_WEBRTC_URL="http://192.168.88.10:8889"
export RECORDINGS_DIR="/recordings" export RECORDINGS_DIR="/recordings"
``` ```
Nếu MediaMTX API có auth, export biến môi trường: Nếu MediaMTX API có auth, set trong `.env`:
```bash - `MEDIAMTX_API_USER`
export MEDIAMTX_API_USER="..." - `MEDIAMTX_API_PASS`
export MEDIAMTX_API_PASS="..."
```
### 3.3 Chạy backend ### 3.3 Chạy backend
```bash ```bash
source api/.venv/bin/activate source api/.venv/bin/activate
uvicorn api.app.main:app --host 0.0.0.0 --port 8008 python3 api/run.py
``` ```
## 4) Frontend (build static) ## 4) Frontend (build static)
@@ -228,9 +234,8 @@ After=network.target
[Service] [Service]
WorkingDirectory=/opt/ipcam-dashboard WorkingDirectory=/opt/ipcam-dashboard
Environment=MEDIAMTX_API_USER= EnvironmentFile=/opt/ipcam-dashboard/.env
Environment=MEDIAMTX_API_PASS= ExecStart=/opt/ipcam-dashboard/api/.venv/bin/python /opt/ipcam-dashboard/api/run.py
ExecStart=/opt/ipcam-dashboard/api/.venv/bin/uvicorn api.app.main:app --host 0.0.0.0 --port 8008
Restart=always Restart=always
RestartSec=2 RestartSec=2
+11 -1
View File
@@ -25,13 +25,21 @@ Dashboard giám sát camera IP gọn nhẹ chạy trên Orange Pi, dựa trên M
## Chạy dev (máy dev) ## Chạy dev (máy dev)
### 0) Tạo file .env
```bash
cp .env.example .env
```
Sửa các biến trong `.env` theo IP/port thực tế (MediaMTX, recordings, CORS).
### 1) Chạy backend ### 1) Chạy backend
```bash ```bash
python3 -m venv api/.venv python3 -m venv api/.venv
source api/.venv/bin/activate source api/.venv/bin/activate
pip install -r api/requirements.txt pip install -r api/requirements.txt
uvicorn api.app.main:app --host 0.0.0.0 --port 8008 python3 api/run.py
``` ```
### 2) Chạy frontend ### 2) Chạy frontend
@@ -45,6 +53,8 @@ Frontend dev server đã được cấu hình proxy `/api` và `/videos` sang `h
## Cấu hình ## Cấu hình
Khuyến nghị cấu hình bằng file `.env` (copy từ `.env.example`).
Backend tự tạo file cấu hình tại `api/data/config.json` khi chạy lần đầu. Backend tự tạo file cấu hình tại `api/data/config.json` khi chạy lần đầu.
- `mediamtx_api_url`: ví dụ `http://127.0.0.1:9997` - `mediamtx_api_url`: ví dụ `http://127.0.0.1:9997`
+7
View File
@@ -23,6 +23,13 @@ from .models import (
from .recordings import list_recordings from .recordings import list_recordings
from .scheduler import Scheduler from .scheduler import Scheduler
try:
from dotenv import load_dotenv
load_dotenv(Path(__file__).resolve().parents[2] / ".env")
except Exception:
pass
def _cors_origins() -> list[str]: def _cors_origins() -> list[str]:
raw = os.getenv("CORS_ORIGINS", "http://localhost:5173") raw = os.getenv("CORS_ORIGINS", "http://localhost:5173")
+1
View File
@@ -3,4 +3,5 @@ uvicorn[standard]>=0.27
httpx>=0.27 httpx>=0.27
pydantic>=2.6 pydantic>=2.6
python-multipart>=0.0.9 python-multipart>=0.0.9
python-dotenv>=1.0.1
+22
View File
@@ -0,0 +1,22 @@
from __future__ import annotations
import os
from pathlib import Path
import uvicorn
try:
from dotenv import load_dotenv
load_dotenv(Path(__file__).resolve().parents[1] / ".env")
except Exception:
pass
def main() -> None:
port = int(os.getenv("DASHBOARD_PORT", "8008"))
uvicorn.run("api.app.main:app", host="0.0.0.0", port=port, reload=False)
if __name__ == "__main__":
main()