33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
# --- main.py ---
|
|
import os
|
|
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.responses import HTMLResponse
|
|
|
|
# 引入我們剛剛拆分出來的路由模組
|
|
from routers import query, config, terminal, lock
|
|
|
|
app = FastAPI(title="Harmonic CMTS Manager", version="2.0")
|
|
|
|
# 掛載靜態檔案目錄 (對應 static/style.css 與 static/app.js)
|
|
app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
|
|
# 註冊 API 路由
|
|
app.include_router(query.router, prefix="/api/v1", tags=["Query"])
|
|
app.include_router(config.router, prefix="/api/v1", tags=["Config"])
|
|
app.include_router(terminal.router, tags=["Terminal"])
|
|
app.include_router(lock.router, prefix="/api/v1/locks")
|
|
|
|
# 根目錄路由:回傳前端 UI
|
|
@app.get("/", response_class=HTMLResponse, tags=["UI"])
|
|
async def read_root():
|
|
# 讀取同層級的 index.html
|
|
html_path = os.path.join(os.path.dirname(__file__), "index.html")
|
|
with open(html_path, "r", encoding="utf-8") as f:
|
|
return f.read()
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
# 啟動伺服器
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8001, reload=True)
|