feat: FastAPI 主入口
This commit is contained in:
parent
f673a8a6d6
commit
096580bdc3
|
|
@ -0,0 +1,74 @@
|
||||||
|
"""
|
||||||
|
NAC 一键上链系统 - 主入口
|
||||||
|
版本: 3.0 (真实注册/登录 + 多语言 + 17步工作流)
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import logging
|
||||||
|
from fastapi import FastAPI
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
from fastapi.responses import FileResponse
|
||||||
|
# 路由模块
|
||||||
|
from routers import assets, onboarding, node
|
||||||
|
from routers.users import router as users_router
|
||||||
|
|
||||||
|
# 日志配置
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.INFO,
|
||||||
|
format='%(asctime)s [%(name)s] %(levelname)s: %(message)s',
|
||||||
|
handlers=[
|
||||||
|
logging.StreamHandler(),
|
||||||
|
logging.FileHandler('/opt/nac/onboarding/logs/app.log', encoding='utf-8')
|
||||||
|
]
|
||||||
|
)
|
||||||
|
logger = logging.getLogger('nac-onboarding')
|
||||||
|
|
||||||
|
app = FastAPI(
|
||||||
|
title='NAC 一键资产上链系统',
|
||||||
|
description='基于NAC公链的RWA资产上链平台 - 17步完整工作流',
|
||||||
|
version='3.0.0',
|
||||||
|
docs_url='/api/docs',
|
||||||
|
redoc_url='/api/redoc'
|
||||||
|
)
|
||||||
|
|
||||||
|
# CORS
|
||||||
|
app.add_middleware(
|
||||||
|
CORSMiddleware,
|
||||||
|
allow_origins=['*'],
|
||||||
|
allow_credentials=True,
|
||||||
|
allow_methods=['*'],
|
||||||
|
allow_headers=['*'],
|
||||||
|
)
|
||||||
|
|
||||||
|
# API路由注册
|
||||||
|
app.include_router(users_router, prefix='/api/users', tags=['用户认证'])
|
||||||
|
app.include_router(assets.router, prefix='/api/assets', tags=['资产管理'])
|
||||||
|
app.include_router(onboarding.router, prefix='/api/onboarding', tags=['上链流程'])
|
||||||
|
app.include_router(node.router, prefix='/api/node', tags=['节点状态'])
|
||||||
|
|
||||||
|
@app.get('/api/health')
|
||||||
|
async def health():
|
||||||
|
from database import db
|
||||||
|
try:
|
||||||
|
await db.command('ping')
|
||||||
|
mongo_status = 'connected'
|
||||||
|
except Exception:
|
||||||
|
mongo_status = 'disconnected'
|
||||||
|
return {
|
||||||
|
'status': 'ok',
|
||||||
|
'version': '3.0.0',
|
||||||
|
'mongo': mongo_status,
|
||||||
|
'protocol': 'NAC-Lens/4.0',
|
||||||
|
'auth': 'local-jwt'
|
||||||
|
}
|
||||||
|
|
||||||
|
# 前端静态文件服务
|
||||||
|
frontend_dir = '/opt/nac/onboarding/frontend'
|
||||||
|
if os.path.exists(frontend_dir):
|
||||||
|
app.mount('/assets', StaticFiles(directory=f'{frontend_dir}/assets'), name='assets')
|
||||||
|
@app.get('/{full_path:path}')
|
||||||
|
async def serve_frontend(full_path: str):
|
||||||
|
index = f'{frontend_dir}/index.html'
|
||||||
|
if os.path.exists(index):
|
||||||
|
return FileResponse(index)
|
||||||
|
return {'error': '前端未构建'}
|
||||||
Loading…
Reference in New Issue