54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
import json
|
||
import os
|
||
import uuid
|
||
import time
|
||
import multiprocessing
|
||
import sys
|
||
|
||
import uvicorn
|
||
from fastapi import FastAPI
|
||
from fastapi.staticfiles import StaticFiles
|
||
from fastapi.middleware.cors import CORSMiddleware
|
||
from file_manager_api import router as file_manager_router
|
||
from utils.logger import logger
|
||
|
||
# Import route modules
|
||
from routes import chat, files, projects, system
|
||
|
||
# Import the system manager from routes.system to access the initialized components
|
||
from routes.system import agent_manager, connection_pool, file_cache
|
||
|
||
app = FastAPI(title="Database Assistant API", version="1.0.0")
|
||
|
||
# 挂载public文件夹为静态文件服务
|
||
app.mount("/public", StaticFiles(directory="public"), name="static")
|
||
|
||
# 添加CORS中间件,支持前端页面
|
||
app.add_middleware(
|
||
CORSMiddleware,
|
||
allow_origins=["*"], # 在生产环境中应该设置为具体的前端域名
|
||
allow_credentials=True,
|
||
allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "PATCH"],
|
||
allow_headers=[
|
||
"Authorization", "Content-Type", "Accept", "Origin", "User-Agent",
|
||
"DNT", "Cache-Control", "Range", "X-Requested-With"
|
||
],
|
||
)
|
||
|
||
# Include all route modules
|
||
app.include_router(chat.router)
|
||
app.include_router(files.router)
|
||
app.include_router(projects.router)
|
||
app.include_router(system.router)
|
||
|
||
# 注册文件管理API路由
|
||
app.include_router(file_manager_router)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
# 启动 FastAPI 应用
|
||
print("Starting FastAPI server...")
|
||
print("File Manager API available at: http://localhost:8001/api/v1/files")
|
||
print("Web Interface available at: http://localhost:8001/public/file-manager.html")
|
||
uvicorn.run(app, host="0.0.0.0", port=8001)
|