feat(deploy): 正式環境部署設定
- frontend/api.js: API URL 自動判斷 (localhost=dev, 其他=相對路徑 /api/v1) - main.py: 加入 StaticFiles 掛載 admin-portal,CORS 開放 - schedule_tenant: Traefik 路由範本更新 - 管理租戶加入 /api 路由 (priority 200) - /admin 加入 StripPrefix middleware - admin 服務改指向 vmis-backend:10281 - docker/vmis: 新增 Dockerfile + docker-compose.yml Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import os
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from app.core.database import SessionLocal
|
||||
from app.services.seed import seed_initial_data
|
||||
@@ -31,7 +33,7 @@ app = FastAPI(
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["http://localhost:10280", "http://localhost:10290"],
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
@@ -43,3 +45,9 @@ app.include_router(api_router, prefix="/api/v1")
|
||||
@app.get("/health")
|
||||
def health():
|
||||
return {"status": "ok", "service": "vmis-backend"}
|
||||
|
||||
|
||||
# 靜態前端(admin portal)— 掛載在最後,讓 API 路由優先
|
||||
_frontend_dir = os.path.join(os.path.dirname(__file__), "..", "frontend")
|
||||
if os.path.isdir(_frontend_dir):
|
||||
app.mount("/", StaticFiles(directory=_frontend_dir, html=True), name="frontend")
|
||||
|
||||
@@ -195,13 +195,33 @@ def _generate_tenant_route_yaml(tenant, is_active: bool) -> str:
|
||||
domain = tenant.domain
|
||||
nc_url = f"http://nc-{code}:80" if is_active else f"http://nc-{code}-test:80"
|
||||
|
||||
lines = ["http:", " routers:"]
|
||||
lines = ["http:"]
|
||||
|
||||
if tenant.is_manager:
|
||||
lines += [
|
||||
" middlewares:",
|
||||
" vmis-strip-admin:",
|
||||
" stripPrefix:",
|
||||
' prefixes: ["/admin"]',
|
||||
"",
|
||||
]
|
||||
|
||||
lines += [" routers:"]
|
||||
|
||||
if tenant.is_manager:
|
||||
lines += [
|
||||
f" {code}-admin:",
|
||||
f' rule: "Host(`{domain}`) && PathPrefix(`/admin`)"',
|
||||
f" service: {code}-admin",
|
||||
f" service: {code}-vmis",
|
||||
" entryPoints: [websecure]",
|
||||
" middlewares: [vmis-strip-admin]",
|
||||
" tls:",
|
||||
" certResolver: letsencrypt",
|
||||
" priority: 200",
|
||||
"",
|
||||
f" {code}-api:",
|
||||
f' rule: "Host(`{domain}`) && PathPrefix(`/api`)"',
|
||||
f" service: {code}-vmis",
|
||||
" entryPoints: [websecure]",
|
||||
" tls:",
|
||||
" certResolver: letsencrypt",
|
||||
@@ -232,10 +252,10 @@ def _generate_tenant_route_yaml(tenant, is_active: bool) -> str:
|
||||
|
||||
if tenant.is_manager:
|
||||
lines += [
|
||||
f" {code}-admin:",
|
||||
f" {code}-vmis:",
|
||||
" loadBalancer:",
|
||||
" servers:",
|
||||
' - url: "http://10.1.0.245:10280"',
|
||||
' - url: "http://vmis-backend:10281"',
|
||||
]
|
||||
|
||||
return "\n".join(lines) + "\n"
|
||||
|
||||
Reference in New Issue
Block a user