Front End Use of the Rest API?
So PWA's are a thing now, and I've been testing out the PLC next for our facility. I started to set up a PWA to hit the rest API for PLC Next and got a good old CORS error:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
I'm looking to see what technology PLC Next uses for its app server, but as it is now, I don't think a PWA (or any other browser based front end) can hit the REST API.
Anyone else see this before? Any chance the REST api can be updated to accept the CORS standard?
Best,
No 'Access-Control-Allow-Origin' header is present on the requested resource.
I'm looking to see what technology PLC Next uses for its app server, but as it is now, I don't think a PWA (or any other browser based front end) can hit the REST API.
Anyone else see this before? Any chance the REST api can be updated to accept the CORS standard?
Best,
Comments
A good starting point is:
How to create a VueJS PWA on a high performance, secure NGINX infrastructure
https://www.freecodecamp.org/news/vuejs-pwa-on-nginx-22360ee7a7bf/
We're happy to help further if you need any more information.
The info you provided is sort of a basic overview of these technologies. I spent the weekend spelunking your architecture and still cannot pass muster with CORs in a browser. Let me give you my findings so far.
This is currently the result being produced by the browser:
The architecture and pathing for the res API is based on nginx and fastCGI. The concerned configurations I have tracked down here:
I have modified these configs to the following:
nginx.conf
nginx_ehmi_location.conf
I have also rebuilt the SSL cert so that it will pass muster with browsers. This gist here is that we needed this line "subjectAltName = IP:192.168.1.10".
SSL.conf
Based on all these changes I still get the CORs error in the browser. However, you can see if I call the api directly from something like Postman, I do get the appropriate headers:
Request
Response
So you can see that this works, not sure why the browsers are still not working.
Here is some information on your latest question:
If there are no answers on this topic from the PLCnext Community, perhaps you can try a general nginx forum.
I was able to resolve this finally. The crux of the issue was that Chrome and Firefox where I tested these both had very specific requirements for accepting a root SSL certificate in combination with a CORS request. I tried a number of certificate configs, and this is what actually worked for future reference:
ssl.conf
Also, it should be noted in my examples from he previous posts, I did also have one mistake. In nginx I used the request header by accident:
That should actually be:
I will pass this information on to the relevant people here, in case anyone else has a similar issue.
Thanks again, and enjoy the weekend.