TheCoder4eu / BootsFaces-OSP

BootsFaces - Open Source Project
Apache License 2.0
247 stars 102 forks source link

Cross Origin Resource Sharing Error with DataTable #1130

Closed christophenoel closed 4 years ago

christophenoel commented 4 years ago

Hello,

As soon as you're working in Development PROJECT_STAGE (which is very useful to develop) in your JSF Web.xml you get CORS domain errors related to the use of bootsfaces datatable.

First, I tried to solve this by adding a CORS filter, but I believe this is generated in the other direction: the remote eval script (for example from cdn.datatables.net) try to send data to the local host. To be honest, I don't really catch the problem, I only can report what happens.

The following errors are reported in the browser (additionally to some popups that you get from the application)

Access to XMLHttpRequest at 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Access to XMLHttpRequest at 'https://cdn.datatables.net/v/bs/jszip-2.5.0/dt-1.10.18/af-2.3.2/b-1.5.4/b-colvis-1.5.4/b-html5-1.5.4/b-print-1.5.4/fc-3.2.5/fh-3.1.4/r-2.2.2/rr-1.2.4/sc-1.5.0/sl-1.2.6/datatables.min.js' from origin 'http://localhost:8080' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.

Any tip to workaround that ? Browser CORS plugins doesn't fix that. My only idea is stopping working with Bootsfaces datatable for now.

Thanks for your support.

stephanrauh commented 4 years ago

I think there's a simple workaround:

Put a local copy of the DataTable JavaScript and CSS code. Download the files from Datatables.net and include them like so:

<h:outputScript library="whatever" name="*datatables*.js />
<h:outputStylesheet name="*datatables*.css />
stephanrauh commented 4 years ago

@spacebel I've tried to reproduce the bug, but I failed. Am I missing something?

stephanrauh commented 4 years ago

@spacebel Can you help me? Otherwise I'm going to close the issue. I can't fix an error that doesn't happen on my machine. Please give me a hint how to reproduce the bug.

christophenoel commented 4 years ago

Dear Stephan, after a long time, I have been again working on this app. I just found that TomEE 8 causes the issue while there is no problem when using 7.1 Moreover, when using TomEE 8 it is reported that synchronous XMLHTTPRequest is deprecated.

If I can find a workaround for TomEE 8, I will report it to you.

Regards, Christophe.

stephanrauh commented 4 years ago

Oh, that might explain why I couldn't reproduce the bug. Thanks for telling us!

Best regards, Stephn