After a lot of trial and error - hours, in fact - I was able to figure out a way to do this within my development environment! Hi Ben, thanks for the insights you presented. So, again, I wonder if there’s an elegant way to do this within nginx config? Even with my React app using localhost:3000 and Local using localhost:10003 I am running into the same error: Access to XMLHttpRequest at ‘ from origin ‘ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. My apologies, I spoke too soon, and didn’t test properly. Thanks again, and if you have any further insights into making changes within the nginx config files that might help me, I’m all ears I’m not sure if it’s a limitation of local development, or if it’s just something that hadn’t been considered, but I do think this feature could aide in deeper integrations, especially by those of us who use Flywheel hosting and want to ensure our local environment is as close to production as possible. I still believe there’s a more elegant solution within the nginx config files, and perhaps this conversation should be moved into the Feature reqeusts category. Thanks Ben, this seemed to work! At least it’s a temporary solution so I can remove that Chrome plugin and browse the web safely. So I’m looking for an elegant solution, and I believe editing the nginx configuration files would be that solution. 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. 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. But when adding this to the 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 tried multiple ways, following directions on Enable CORS and other sites that show the same code. However, in development mode it will run on 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. In production, CORS will not be an issue because the React app will run on the same domain and port number as the website. 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?īackstory: 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |