Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

46 wiersze
1.2 KiB

2 lat temu
  1. import logging
  2. import os
  3. from flask import Flask
  4. from flask import Blueprint
  5. from flask import request
  6. from be.view import auth
  7. from be.view import seller
  8. from be.view import buyer
  9. from be.model.store import init_database
  10. bp_shutdown = Blueprint("shutdown", __name__)
  11. def shutdown_server():
  12. func = request.environ.get("werkzeug.server.shutdown")
  13. if func is None:
  14. raise RuntimeError("Not running with the Werkzeug Server")
  15. func()
  16. @bp_shutdown.route("/shutdown")
  17. def be_shutdown():
  18. shutdown_server()
  19. return "Server shutting down..."
  20. def be_run():
  21. this_path = os.path.dirname(__file__)
  22. parent_path = os.path.dirname(this_path)
  23. log_file = os.path.join(parent_path, "app.log")
  24. init_database(parent_path)
  25. logging.basicConfig(filename=log_file, level=logging.ERROR)
  26. handler = logging.StreamHandler()
  27. formatter = logging.Formatter(
  28. "%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s"
  29. )
  30. handler.setFormatter(formatter)
  31. logging.getLogger().addHandler(handler)
  32. app = Flask(__name__)
  33. app.register_blueprint(bp_shutdown)
  34. app.register_blueprint(auth.bp_auth)
  35. app.register_blueprint(seller.bp_seller)
  36. app.register_blueprint(buyer.bp_buyer)
  37. app.run()