app.py 1.2 KB

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