Hello there, I realize this is an edge case, but I’m wondering if there is a way to add a CORS policy to the nginx config file for either the full site, or alternately the /wp-json/ portion of the site?
Backstory: I am running a React app locally using a project that was bootstrapped with Create React App, so I’m pretty much tied to this environment. In production, CORS will not be an issue because the React app will run on the same domain and port number as the website. However, in development mode it will run on http://localhost:3000. This is a requirement, and although I can run it using my Local site domain, the port number still needs to be 3000 or a unique number of my choosing - point is, it cannot be the same port number as Local (e.g. https://mylocaladdress.local:3000).
I’ve tried multiple ways, following directions on Enable CORS and other sites that show the same code. But when adding this to the site.conf.hbs file and restarting the server I get the typical 502 Request Error message, so this is either conflicting with global code or just not written correctly for the Local nginx environment. I’ve also tried to add code as found on this website, but again it doesn’t work because I believe it’s checking the CORS policy on the server-level before even hitting this code.
I have bypassed this for the time being by adding a Chrome extension called “Allow CORS: Access-Control-Allow-Origin” however I fear this could expose me to security vulnerabilities if I forget to disable this while navigating to other websites. So I’m looking for an elegant solution, and I believe editing the nginx configuration files would be that solution. I appreciate any insights!
Local version 5.7.5+4909
macOS Catalina version 10.15.7
Nginx web server
PHP 7.4.1
MySQL 8.0.16
WP 5.5.1