feat : 代码梳理 移除所有敏感密钥 通过环境变量方式配置
All checks were successful
git commit AiDA python develop 分支构建部署 / scheduled_deploy (push) Has been skipped

This commit is contained in:
zcr
2025-12-30 16:49:08 +08:00
parent 1be716e414
commit 18024a2d70
167 changed files with 5283 additions and 10464 deletions

View File

@@ -1,10 +1,17 @@
# 1. 这里的顺序至关重要!必须在最顶端
import sys
try:
import asyncore
except ImportError:
import pyasyncore
sys.modules['asyncore'] = pyasyncore
import logging.config
import uvicorn
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.cron import CronTrigger
from fastapi import FastAPI
from fastapi import HTTPException, Request
from fastapi import HTTPException
from fastapi.responses import JSONResponse
from app.api.api_route import router
@@ -12,19 +19,22 @@ from app.core.config import settings
from app.core.record_api_count import count_api_calls
from app.schemas.response_template import ResponseModel
from logging_env import LOGGER_CONFIG_DICT
from dotenv import load_dotenv
from starlette.middleware.cors import CORSMiddleware
logging.config.dictConfig(LOGGER_CONFIG_DICT)
logging.getLogger("pika").setLevel(logging.WARNING)
from starlette.middleware.cors import CORSMiddleware
logger = logging.getLogger(__name__)
load_dotenv()
def get_application() -> FastAPI:
application = FastAPI(
title=settings.PROJECT_NAME, docs_url="/docs", redoc_url='/re-docs',
openapi_url=f"{settings.API_PREFIX}/openapi.json",
docs_url="/docs",
redoc_url='/re-docs',
openapi_url=f"/openapi.json",
description='''
Base frame with FastAPI
- Super Resolution API
@@ -33,13 +43,13 @@ def get_application() -> FastAPI:
)
application.add_middleware(
CORSMiddleware,
allow_origins=[str(origin) for origin in settings.BACKEND_CORS_ORIGINS],
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
application.middleware("http")(count_api_calls)
application.include_router(router=router, prefix=settings.API_PREFIX)
application.include_router(router=router)
return application
@@ -47,14 +57,12 @@ app = get_application()
@app.exception_handler(HTTPException)
async def http_exception_handler(request: Request, exc: HTTPException):
async def http_exception_handler(exc: HTTPException):
return JSONResponse(
status_code=exc.status_code,
content=ResponseModel(code=exc.status_code, msg=exc.detail, data=exc.detail).dict()
)
if __name__ == '__main__':
uvicorn.run(app, host="0.0.0.0", port=8000)
uvicorn.run(app, host="0.0.0.0", port=settings.PORT)