06-24-2021 04:59 PM
I'm writing a custom web application that will be utilizing SystemLink's REST API. I'm unable to use any of the API calls in my development environment due to CORS. See below error message:
Access to XMLHttpRequest at 'https://systemlink.local/login/login-redirect' (redirected from 'https://systemlink.local/nitestmonitor/v2/products') from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
I've already enabled CORS for all origins through NI Web Server, but I'm still running into this error. A quick Google search suggest that SystemLink is still attempting to authenticate the CORS preflight request (https://stackoverflow.com/a/42172732).
I don't believe this isn't an issue with my web app, because I'm able to host it on the SystemLink web server and the CORS issue goes away. This error message only applies when I try to do local development on my computer.
Is there any way where I can configure this so that this issue goes away? The workaround at the moment is pretty annoying.
Solved! Go to Solution.
06-25-2021 08:55 AM
You may want to check out this document if you haven't already. It is mainly focused on creating custom web applications using NXG Web Module, however it has some generic information as well.
Even with CORS enabled, you will still need to ensure your application is passing in the appropriate credentials.
06-25-2021 09:28 AM - edited 06-25-2021 09:31 AM
Sorry, posted as test profile 🙂
06-25-2021 09:31 AM
From what I see, you are developing you app using Angular (Angular's default port is 4200). First, please try to add the following configuration under the proxy configuration file that you have setup in your Angular aplication:
Note: I have the name of the server machine under the "Prefered host name for generated URLs and ceritifaces" but I believe that is only used when using HTTPS.
Lastly, I am currently using HTTP. You might end up with some certificate issues with HTTPS and Angular (clients don't automatically trust self-signed certificates when you create them in the "HTTPS" tab). However if you really want to use HTTPS with self-signed certificates, I found a blogpost where you can find how to configure your angular proxy to trust the certificate -> https://medium.com/medialesson/debug-angular-apps-locally-with-a-self-signed-ssl-certificate-9819158...
Hope this helps
06-28-2021 11:20 AM
Thanks for the answers! Setting up the proxy for Angular worked out great.