Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Cors error #2132

Closed
3 tasks
indraraj26 opened this issue Nov 2, 2019 · 4 comments · Fixed by #2146
Closed
3 tasks

bug: Cors error #2132

indraraj26 opened this issue Nov 2, 2019 · 4 comments · Fixed by #2146

Comments

@indraraj26
Copy link

Bug Report

Capacitor Version

npx cap doctor output:

npx cap doctor
   Capacitor Doctor
Latest Dependencies:
  @capacitor/cli: 1.3.0
  @capacitor/core: 1.3.0
  @capacitor/android: 1.3.0
  @capacitor/ios: 1.3.0

Installed Dependencies:
  @capacitor/ios not installed
  @capacitor/cli 1.3.0
  @capacitor/core 1.3.0
  @capacitor/android 1.3.0

Affected Platform(s)

  • [X ] Android
  • iOS
  • Electron
  • Web

Current Behavior

Getting cors error in real device even cors is already enabled at backend side. With ionic 3 it is working fine.

Access to XMLHttpRequest at 'https://xxx.xx.xxx/getuser' from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource

I have set this in capacitor.config.json

  "android": {
    "allowMixedContent": true
  }

Expected Behavior

It should work like ionic 3.

Sample Code or Sample Application Repo

Reproduction Steps

Other Technical Details

npm --version output: 6.9.0

node --version output: v10.16.3

pod --version output (iOS issues only):

Other Information

ionic info

Ionic:

   Ionic CLI                     : 5.4.4 (C:\Users\indra26\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework               : @ionic/angular 4.11.2
   @angular-devkit/build-angular : 0.801.3
   @angular-devkit/schematics    : 8.1.3
   @angular/cli                  : 8.1.3
   @ionic/angular-toolkit        : 2.0.0

Capacitor:

   Capacitor CLI   : 1.3.0
   @capacitor/core : 1.3.0

Utility:

   cordova-res : 0.8.0
   native-run  : 0.2.9

System:

   NodeJS : v10.16.3 (C:\Program Files\nodejs\node.exe)
   npm    : 6.9.0
   OS     : Windows 10
@pklime2
Copy link

pklime2 commented Nov 2, 2019

I'm seeing a similar issue on Android only since upgrading to v1.3.0. From what I can tell based on the logs it may be related to this change

ccc00b3
Specifically line 175 of android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java

The logs indicate that my server's API URL is being treated as a local request and is calling handleLocalRequest instead of handleProxyRequest. In my case the "server.url" property is not set in capacitor.config.json which means this is always evaluating to true.

I'm not 100% certain this is the case, but I'm going to downgrade to v1.2.1 in the interim. I have validated that the issue is not present for me on this version.

@indraraj26
Copy link
Author

indraraj26 commented Nov 2, 2019

Hi @pklime2 ,

Can you share your capacitor.config.json, i am not sure whether i will have to add

 server :{
url:'yourdomain'
} 

btw what is the purpose of this server url.

Thank you

@pklime2
Copy link

pklime2 commented Nov 5, 2019

This is what I currently have set

{
  "appId": "com.myapp",
  "appName": "App",
  "bundledWebRuntime": false,
  "npmClient": "npm",
  "webDir": "www",
  "server": {
    "allowNavigation": [
      "*.mydomain.com"
    ]
  },
  "plugins": {
    "Keyboard": {
      "resize": "ionic"
    },
    "SplashScreen": {
      "launchAutoHide": false
    }
  }
}

Based on the documentation it looks like the server.url property is used for loading a local web server for live reloading (e.g. Angular), but in my case I'm seeing this error on a build created using ionic build --prod.

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 13, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants