32 lines
882 B
Python
32 lines
882 B
Python
from fastapi import FastAPI, WebSocket
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from app.api.v1.api import api_router
|
|
from app.core.config import settings
|
|
# from app.services.websocket_service import websocket_service
|
|
|
|
app = FastAPI(
|
|
title="温度数据采集系统",
|
|
description="温度数据采集系统API接口",
|
|
version="1.0.0"
|
|
)
|
|
|
|
# 配置CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"], # 在生产环境中应该设置具体的域名
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# 注册路由
|
|
app.include_router(api_router)
|
|
|
|
# @app.websocket("/ws")
|
|
# async def websocket_endpoint(websocket: WebSocket):
|
|
# """WebSocket端点"""
|
|
# await websocket_service.handle_websocket(websocket)
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {"message": "温度数据采集系统API服务正在运行"} |