Search code examples
vuejs2axioscapacitor

How to run Capacitor iOS app from local build while communicating with server for data requests


I am building an iOS app from an existing Vue/Laravel based project. I have found that by configuring capacitor.config.json with:

{
  "bundledWebRuntime": false,
  "webDir": "public",
  "server": {
    "url": "http://192.168.99.100" //the location of my docker server
  }
}

that I can get the index.html and app.js bundle from the Laravel server and run the app fine that way. However this seems to defeat much of the purpose of bundling and deploying an application such as saving the latency for fetching app.js etc.

If I remove the "server" field from capacitor.config.json, then the app runs from the built version of app.js and index.html found locally on the iOS device. However, I find that I can no longer communicate with the Laravel server for data requests even when configuring the baseUrl for axios to the same http://192.168.99.100


Solution

  • This had nothing to do with Axios. Rather I needed to enable CORS for the iOS device, which I did using the spatie/laravel-cors package.