app.py 1.3 KB

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