app.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from flask import Flask, request
  2. from flask_cors import CORS
  3. import json
  4. import os.path
  5. from engine.handle_request import handleSimpleGetQuery
  6. app = Flask(__name__)
  7. CORS(app) # This will enable CORS for all routes
  8. # CORS enabling is useful to prevent annoying CORS error when developing locally
  9. # Configuration for the app, particularly for DB & other possible data provider(s)
  10. # Eventually should be put in a config file (or similar general solution)
  11. dataConfig = {
  12. 'appath': app.root_path,
  13. 'dbpath': os.path.join(app.root_path, os.pardir) + '/db/first_db/test1.db',
  14. 'data_interface': 'sqlite3'
  15. }
  16. # ADD LOGGING?
  17. ################################################################
  18. # parte di codice da copiare per fare un altro endpoint in Flask
  19. @app.route('/simple_get_query', methods=['POST'])
  20. def simpleQuery():
  21. # This is a stupid (and possibly TEMPORARY) way of handling the JSON data, but it works;
  22. # trying to send application/json data causes Flask to complain and I can't understand why!
  23. jsonString = json.loads( request.form['stringifiedDTO'] )
  24. queryDTO = jsonString['queryList']
  25. # UP TO HERE
  26. try:
  27. output = handleSimpleGetQuery(queryDTO, dataConfig)
  28. return output, 200
  29. except Exception as err:
  30. # Log the exception? Send it back to FE?
  31. emptyOut = {}
  32. return emptyOut, 500
  33. # fino a qui
  34. #################################################################
  35. if __name__ == '__main__':
  36. app.run()