Răsfoiți Sursa

added CORS flask for tests

ash 2 ani în urmă
părinte
comite
3fc1616bee

+ 3 - 0
Backend/Design/api urls catalog.txt

@@ -19,6 +19,7 @@ api/inventory/site/<site_id> - GET get site by id
 api/inventory/site/<site_id> - UPDATE  site by id
 api/inventory/site/<site_id> - DELETE site by id
 api/inventory/site/template GET get null item template json
+api/inventory/site/<int:siteID>/items GET associated items with this
 
 api/inventory/contacts - GET -> get all contact
 api/inventory/contact - POST create contact
@@ -26,6 +27,7 @@ api/inventory/contact/<contact_id> - GET get contact by id
 api/inventory/contact/<contact_id> - UPDATE  contact by id
 api/inventory/contact/<contact_id> - DELETE contact by id
 api/inventory/contact/template GET get null item template json
+api/inventory/contact/<int:siteID>/items GET associated items with this
 
 api/inventory/groups - GET -> get all groups with items array id
 api/inventory/group - POST create group with items ids
@@ -34,3 +36,4 @@ api/inventory/group/<contact_id>/item/<item_id> - POST  add item to group
 api/inventory/group/<contact_id>/item/<item_id> - DELETE  delete item to group
 api/inventory/group/<contact_id> - DELETE group by id
 api/inventory/group/template GET get null item template json
+api/inventory/group/<int:siteID>/items GET associated items with this

+ 5 - 5
Backend/Sources/View/view_manager.py

@@ -2,7 +2,7 @@ from array import array
 import threading
 from flask import session,Flask,request, jsonify
 import flask
-
+import flask_cors
 
 import persistence
 import Model.isp_model as isp_model
@@ -27,7 +27,7 @@ __app__.secret_key = "aseqzdwxc"
 __app__.permanent_session_lifetime = timedelta(minutes=2)
 __app__.logger = logger
 __app__.config['JSONIFY_PRETTYPRINT_REGULAR'] = True
-
+flask_cors.CORS(__app__)
 
 
 limiter = Limiter(__app__,key_func=get_remote_address,default_limits=["100 per minute"])
@@ -68,9 +68,9 @@ def after_request(response : flask.Response):
     # adding this to the header to allow cross origin
     # for exemple origin cross origin is when website with javascript has it's server (origin 1)
     # and the javascript call some request on another server (origin 2), typically our API.
-    header['Access-Control-Allow-Origin'] = '*'
-    header['Access-Control-Allow-Methods'] = 'GET,DELETE,UPDATE,HEAD,OPTIONS,POST,PUT'
-    header['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
+    #header['Access-Control-Allow-Origin'] = '*'
+    #header['Access-Control-Allow-Methods'] = 'GET,DELETE,UPDATE,HEAD,OPTIONS,POST,PUT'
+    #header['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
 
     logger.debug(response.__dict__)