[Vuejs]-CodeIgniter4 + Vue + Webpack devServer CORS

1👍

After trying a bunch of things, I had to add headers to my CodeIgniter Method:

header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
header("Access-Control-Allow-Headers: Content-Type, Content-Length, Accept-Encoding");

0👍

If you want to prevent CORS errors in your local dev environment and access data from other web servers (remote or local), it can be very easily done with the proxy config. This option redirect every request to a local path to a remote URL. https://webpack.js.org/configuration/dev-server/#devserverproxy

You don’t even need a CORS configuration in this case, because you’ll mount an external path on the same local environment, so that the web browser does not complain. The remote address must of course be trustworthy.

Leave a comment