Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS errors #287

Closed
marty-mcgee opened this issue Dec 29, 2020 · 1 comment
Closed

CORS errors #287

marty-mcgee opened this issue Dec 29, 2020 · 1 comment

Comments

@marty-mcgee
Copy link

marty-mcgee commented Dec 29, 2020

Documentation states:

CORS errors

If you have deployed your WordPress install and are having CORS issues be sure to update /wordpress/wp-content/themes/postlight-headless-wp/inc/frontend-origin.php with your frontend origin URL.

However, on a production Linux box, I am still getting CORS errors after updating the theme's "frontend-origin.php" file within the docker container "wordpress", which results in a Connection Timeout. Here are the errors thrown in Chrome.. as Firefox doesn't show this error, but it still occurs..

In dev tools console:

Fetch API cannot load node:net. URL scheme must be "http" or "https" for CORS request.

In browser window:

Error: connect ETIMEDOUT 159.65.79.248:8080 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1138:16)

UPDATES/HINTS:

I have a strong feeling that it is because the "wp-headless" app exposes the root at 8080 as the WordPress API, meaning it serves up http://ip-address-or-domain:8080/wp-json/, which is of content-type 'application/json', which is NOT supported by CORS (see Mozilla article: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS for this and other good info).

So... how do we accept 'application/json' requests over CORS in this "wp-headless" app container? I have tried everything I can think of in ".htaccess", but it doesn't follow the set rules. It also seems to totally ignore the rules set in "frontend-origin.php" code action that filters the headers.

Ultimate question now: How do we allow access to the "wp-headless" site via REST API from the "frontend" site if CORS does not support "application/json" header content-type?

Any help is tremendously appreciated!! Thanks.

@marty-mcgee
Copy link
Author

Alrighty.. after 7 days of perplexing troubleshooting efforts, the solution for me is to assign a Floating IP address to the DigitalOcean droplet instance (Linux server with Docker). I could not ever get past the CORS error using the internal assigned IP address.. I needed an outside-accessible IP address for everything to pass CORS. I'm not exactly sure why yet, but it works this way. Now I have this project up and running in a production environment on DigitalOcean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant