app.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. import argparse
  5. from fastapi import FastAPI
  6. from module.logger import logger
  7. from module.server.home_router import home_app
  8. from module.server.script_router import script_app
  9. app = FastAPI(
  10. title='OAS',
  11. description='OAS web service',
  12. version='0.0.0',
  13. )
  14. app.include_router(home_app)
  15. app.include_router(script_app)
  16. @app.on_event("startup")
  17. async def startup_event():
  18. logger.info('OAS web service startup done')
  19. pass
  20. @app.on_event("shutdown")
  21. async def shutdown_event():
  22. logger.info('OAS web service shutdown done')
  23. def fastapi_app():
  24. parser = argparse.ArgumentParser(description="OAS web service")
  25. parser.add_argument(
  26. "-k", "--key", type=str, help="Password of OAS. No password by default"
  27. )
  28. parser.add_argument(
  29. "--cdn",
  30. action="store_true",
  31. help="Use jsdelivr cdn for pywebio static files (css, js). Self host cdn by default.",
  32. )
  33. parser.add_argument(
  34. "--run",
  35. nargs="+",
  36. type=str,
  37. help="Run OAS by config names on startup",
  38. )
  39. args, _ = parser.parse_known_args()
  40. return app