36 lines
965 B
Python
36 lines
965 B
Python
# coding:utf-8
|
|
import uvicorn
|
|
from fastapi import FastAPI
|
|
from fastapi.exceptions import RequestValidationError
|
|
from fastapi import Response
|
|
from starlette.middleware.cors import CORSMiddleware
|
|
|
|
import schemas
|
|
from api import api_router
|
|
|
|
app = FastAPI(openapi_url='/bale_apk/openapi.json')
|
|
|
|
app.include_router(api_router)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=['*'],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
# @app.exception_handler(RequestValidationError)
|
|
# async def validation_exception_handler(request, exc):
|
|
# return Response(schemas.Msg(code='-1', msg='服务器错误', data=str(exc)), status_code=200)
|
|
#
|
|
#
|
|
# @app.exception_handler(Exception)
|
|
# async def http_exception_handler(request, exc):
|
|
# return Response(schemas.Msg(code='-1', msg='服务器错误'), status_code=200)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
uvicorn.run(app='main:app', host="0.0.0.0", port=7889, reload=True, debug=True)
|