app.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from flask import Flask, request
  2. from flask_cors import CORS
  3. import json
  4. from engine.handle_request import handle_basic_request
  5. app = Flask(__name__)
  6. CORS(app) # This will enable CORS for all routes
  7. # CORS enabling is useful to prevent annoying CORS error when developing locally
  8. ################################################################
  9. # parte di codice da copiare per fare un altro endpoint in Flask
  10. @app.route('/simple_get_query', methods=['POST'])
  11. def simpleQuery():
  12. # This is a stupid way of handling the JSON data, but it works;
  13. # trying to send application/json data causes Flask to complain and I can't understand why!
  14. jsonDTO = json.loads( request.form['stringifiedDTO'] )
  15. appath = app.root_path
  16. try:
  17. queryList = jsonDTO['queryList']
  18. output = handle_basic_request(queryList, appath)
  19. return output, 200
  20. except Exception as err:
  21. emptyOut = {}
  22. return emptyOut, 500
  23. # fino a qui
  24. #################################################################
  25. if __name__ == '__main__':
  26. app.run()