recovered usage of falcon_cors middleware in API
parent
6051c05221
commit
5d0679d60a
|
@ -1,5 +1,5 @@
|
||||||
from falcon_cors import CORS
|
|
||||||
import falcon
|
import falcon
|
||||||
|
from falcon_cors import CORS
|
||||||
from falcon_multipart.middleware import MultipartMiddleware
|
from falcon_multipart.middleware import MultipartMiddleware
|
||||||
from core import energyflowdiagram, privilege, textmessage, distributioncircuit, virtualmeter, \
|
from core import energyflowdiagram, privilege, textmessage, distributioncircuit, virtualmeter, \
|
||||||
costcenter, point, knowledgefile, meter, tariff, user, storetype, timezone, \
|
costcenter, point, knowledgefile, meter, tariff, user, storetype, timezone, \
|
||||||
|
@ -91,34 +91,11 @@ from reports import virtualmetercost
|
||||||
|
|
||||||
# https://github.com/lwcolton/falcon-cors
|
# https://github.com/lwcolton/falcon-cors
|
||||||
# https://github.com/yohanboniface/falcon-multipart
|
# https://github.com/yohanboniface/falcon-multipart
|
||||||
class CORSComponent:
|
cors = CORS(allow_all_origins=True,
|
||||||
|
allow_credentials_all_origins=True,
|
||||||
def process_response(self, req, resp, resource, req_succeeded):
|
allow_all_headers=True,
|
||||||
resp.set_header('Access-Control-Allow-Origin', '*')
|
allow_all_methods=True)
|
||||||
|
api = falcon.App(middleware=[cors.middleware, MultipartMiddleware()])
|
||||||
if (req_succeeded
|
|
||||||
and req.method == 'OPTIONS'
|
|
||||||
and req.get_header('Access-Control-Request-Method')
|
|
||||||
):
|
|
||||||
# NOTE: This is a CORS preflight request. Patch the
|
|
||||||
# response accordingly.
|
|
||||||
|
|
||||||
allow = req.get_header('Access-Control-Request-Method')
|
|
||||||
# resp.delete_header('Allow')
|
|
||||||
|
|
||||||
allow_headers = req.get_header(
|
|
||||||
'Access-Control-Request-Headers',
|
|
||||||
default='*'
|
|
||||||
)
|
|
||||||
|
|
||||||
resp.set_headers((
|
|
||||||
('Access-Control-Allow-Methods', allow),
|
|
||||||
('Access-Control-Allow-Headers', allow_headers),
|
|
||||||
('Access-Control-Max-Age', '86400'), # 24 hours
|
|
||||||
))
|
|
||||||
|
|
||||||
|
|
||||||
api = falcon.App(middleware=[CORSComponent(), MultipartMiddleware()])
|
|
||||||
|
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
# Routes for System Core
|
# Routes for System Core
|
||||||
|
|
Loading…
Reference in New Issue