Search code examples
androidcapacitor

Capacitor - Set origin for cors


Is it possible to set a default origin of https://example.org as opposed to the standard http://localhost on an Android Capacitor app?


Solution

  • The origin is handled by the webview and depends on the url where the app is served, so you can’t change the origin directly, but you can change the url capacitor uses, which will change the origin. To change the url, configure hostname and androidSchene properties of server object in capacitor.config.json

    "server": {
        "hostname": "example.org",
        "androidScheme": "https"
    }
    

    https://capacitor.ionicframework.com/docs/basics/configuring-your-app#common-configuration