main.py 839 B

123456789101112131415161718192021222324252627282930313233343536
  1. from contextlib import asynccontextmanager
  2. from pathlib import Path
  3. from fastapi import FastAPI
  4. import uvicorn
  5. # app = FastAPI()
  6. # @app.get("/")
  7. # async def root():
  8. # return {"message": "Hello World"}
  9. #
  10. #
  11. # @app.get("/hello/{name}")
  12. # async def say_hello(name: str):
  13. # return {"message": f"Hello {name}"}
  14. from core.registrar import register_app
  15. app = register_app()
  16. if __name__ == '__main__':
  17. # 如果你喜欢在 IDE 中进行 DEBUG,main 启动方法会很有帮助
  18. # 如果你喜欢通过 print 方式进行调试,建议使用 fastapi cli 方式启动服务
  19. try:
  20. config = uvicorn.Config(app=f'{Path(__file__).stem}:app', reload=False)
  21. server = uvicorn.Server(config)
  22. server.run()
  23. # uvicorn.run(app, host='127.0.0.1', port=8000)
  24. except Exception as e:
  25. raise e