Allow enabling CORS

Local is mainly for WordPress development.

With the hype on REST API, not providing a way to toggle CORS, seems to be a big miss from Flywheel.

It there any chance you are going to add this feature without suggesting users to play with the configuration files (provided that it’s even possible) every time they need this feature?

Hi Andrea,

Thanks for the heads up on this!

I’ve made a note in our internal tracker to look into this more and come up with a plan of action if needed.

How do you usually use the REST API? Are you accessing the API from the same Local site, other Local sites, or some other setup?

Accessing the API from the same site is not a problem and won’t cause any CORS issue.

I was trying to develop the REST client as a separate ReactJS app, using webpack-dev-server which creates a simple web server for development purposes in localhost:8080.

Now I’m developing the client as part of the same site (basically, as a feature plugin which has both the client and server logic), so everything runs on the same server.
However, this is not the ideal environment for me, as I prefer isolating the two things: the ReactJS does not need the WP site to run, except for when calling the REST API, for which I have the CORS problem.

@misamee,

I just tested out the REST API in both the Preferred and Custom environments and didn’t run into any CORS issues.

If you have time, can you provide the error that you’re running into?

Also, have you tried changing the CORS headers with a snippet like the following? https://gist.github.com/miya0001/d6508b9ba52df5aedc78fca186ff6088

It was a false alarm, after all: https://wordpress.org/support/topic/trying-to-check-if-rest-api-is-active-from-a-plugin-causes-a-time-out/#post-10104023

1 Like