app.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import logging
  2. from flask import Flask
  3. import route.analyze
  4. import route.result
  5. import route.upload
  6. from config import VERSION_PREFIX, MAX_CONTENT_LENGTH, MYSQL_URI
  7. from db import db
  8. from route.util import make_response
  9. app = Flask(__name__)
  10. app.config['MAX_CONTENT_LENGTH'] = MAX_CONTENT_LENGTH
  11. app.config['SQLALCHEMY_DATABASE_URI'] = MYSQL_URI
  12. app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
  13. app.register_blueprint(route.upload.bp, url_prefix=VERSION_PREFIX)
  14. app.register_blueprint(route.analyze.bp, url_prefix=VERSION_PREFIX)
  15. app.register_blueprint(route.result.bp, url_prefix=VERSION_PREFIX)
  16. db.init_app(app)
  17. with app.app_context():
  18. # db.drop_all()
  19. db.create_all()
  20. @app.route("/")
  21. def hello_world():
  22. return "<p>Hello, World!</p>"
  23. @app.errorhandler(413)
  24. def error_handler(e):
  25. logging.exception(e)
  26. return make_response(413, "entity too large, max acceptable: " + str(MAX_CONTENT_LENGTH) + " bytes", {})
  27. @app.errorhandler(404)
  28. def error_handler(e):
  29. logging.exception(e)
  30. return make_response(404, "path not found.", {})
  31. @app.errorhandler(Exception)
  32. def error_handler(e):
  33. logging.exception(e)
  34. return make_response(500, "unknown internal server error.", {})
  35. if __name__ == '__main__':
  36. app.run()