androidionic-frameworkcorsvuejs3

how to overcome CORS error in IONIC Vue 3 android build?


I am using a rest api which has allowed CORS for localhost. When i use the web version of ionic application i get the responses from the server as expected. But when it comes the android emulator it gives me the following error, My Api only allows either from localhost or from my domain. how to overcome this issue?

**Msg: Failed to load https://myapi.com/GetAllUsersList: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost, *', but only one is allowed. Origin 'http://localhost' is therefore not allowed access.**

Solution

  • Replying to my own question!! we can change the url capacitor uses, which will change the origin. we can edit the capasitor.config.json with following properties

    "server": {
        "hostname": "mydomain.com", //in my case this is localhost
        "androidScheme": "https"
    }