Created 11-28-2016 03:45 AM
I have NiFi flow exposed as REST endpoint using ListenHTTP processor. I am able to access the REST endpoint using java client with no issues but when I tried accessing the same endpoint using web application (html/javascript) I am getting following exception.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at <REST end point>. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
Created 12-19-2016 08:28 PM
I am able to resolved this by using XMLHttpRequest object event handlers on the client side application.
Created 12-19-2016 08:28 PM
I am able to resolved this by using XMLHttpRequest object event handlers on the client side application.
Created 06-14-2017 12:35 PM
Hello Milind,
I have run into the same issue and I do not see way how to set 'Access-Control-Allow-Origin' header in ListenHTTP processor.
"Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://XXX' is therefore not allowed access." Could you please share more details how you solved it? Thanks,
Tomas
Created 06-14-2017 01:21 PM
I managed to solve it with jQuery like this:
$.ajax({ url: url, type: "POST", crossDomain: true, data: data, dataType: "json", success:function(result){ alert(JSON.stringify(result)); }, error:function(xhr,status,error){ alert(status); } });
Created 06-14-2017 02:22 PM
The previous was not quite correct - still some errors in browser. Finally I solved it using handleHttpRequest and handleHttpResponse porocessor the latter one returning custom header (aka custom property)access-control-allow-origin:*
Created on 10-21-2019 11:56 PM - edited 10-22-2019 12:03 AM
Hi All, Please let me know validation checkpoints to do this. Still not able to figure out .
Created 04-06-2020 07:40 AM
I'm glad you were able to find a workaround. But if I understand the solution correctly, then we must use JQuery and abandon hopes of using the Fetch API? I would like to use CORS for the added security and feel like this is not a holistic solution. The root issue seems to be that NiFi admins cannot add origins. Is this really the only option?
Created 10-22-2019 12:02 AM
Created 11-05-2019 02:34 AM
Hi,
I added the following on the handle response processor:
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Allow-Origin: *
I also had to allow the options method in the handle http request processor and respond to the options request with this header. You could use wildcards for everything if you are testing.
The browser does a preflight options request for cross origin requests. It does this if it is not classified as a simple request: https://stackoverflow.com/a/40373949/3359365
So if you set the content-type to application/json on the client for a cross origin post the browser will check if the server supports it with the options request.