Browse Source

add cross origin to fix issues in browsers

Sven Czarnian 3 years ago
parent
commit
efae307e84
2 changed files with 9 additions and 1 deletions
  1. 7 0
      aman/app.py
  2. 2 1
      setup.py

+ 7 - 0
aman/app.py

@@ -5,6 +5,7 @@ import os
 import subprocess
 
 from flask import Flask, Response, request
+from flask_cors import CORS, cross_origin
 from json import JSONEncoder
 
 from aman.AMAN import AMAN
@@ -37,10 +38,13 @@ with open(os.path.join(os.environ['AMAN_PATH'], 'VERSION')) as file:
 
 # initialize the web services
 app = Flask('AMAN')
+cors = CORS(app)
+app.config['CORS_HEADERS'] = 'Content-Type'
 if __name__ == '__main__':
     app.run()
 
 @app.route('/aman/airports')
+@cross_origin()
 def airports():
     # get the airports
     retval = []
@@ -73,6 +77,7 @@ def newUser():
     return Response(data, status=200, mimetype='application/json')
 
 @app.route('/aman/configuration/<icao>')
+@cross_origin()
 def configuration(icao):
     airport = aman.findAirport(icao.upper())
     if None == airport:
@@ -105,6 +110,7 @@ def configuration(icao):
     return Response(data, status=200, mimetype='application/json')
 
 @app.route('/aman/sequence/<icao>')
+@cross_origin()
 def sequence(icao):
     airport = aman.findAirport(icao.upper())
     if None == airport:
@@ -125,6 +131,7 @@ def sequence(icao):
     return Response(data, status=200, mimetype='application/json')
 
 @app.route('/aman/configure', methods=['POST'])
+@cross_origin()
 def configure():
     data = request.get_json()
 

+ 2 - 1
setup.py

@@ -98,6 +98,7 @@ setup(
         'pyzmq',
         'scipy',
         'setuptools',
-        'flask'
+        'flask',
+        'flask-cors'
     ]
 )