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

fix(ios): Support CORS when using Live Reload #2882

Closed
wants to merge 1 commit into from
Closed

fix(ios): Support CORS when using Live Reload #2882

wants to merge 1 commit into from

Conversation

diachedelic
Copy link
Contributor

_capacitor_file_ HTTP requests fail CORS checks when server.url is set. This PR implements CORS support on iOS. (Sidenote: does not require a fix for Android as _capacitor_file_ requests are sent to the same origin of the page).

How to reproduce

// capacitor.config.json
{
  "server": { "url": "http://192.168.15.26:6789" }
  ...
}
// my-app.js
const url = Capacitor.convertFileSrc(uri)
await fetch(url) // throws
[Error] Origin http://192.168.15.26:6789 is not allowed by Access-Control-Allow-Origin.
[Error] Failed to load resource: Origin http://192.168.15.26:6789 is not allowed by Access-Control-Allow-Origin. (1588911030406.txt, line 0)
[Error] Fetch API cannot load capacitor://localhost/_capacitor_file_/Users/me/Library/Developer/CoreSimulator/Devices/E60456F7-630E-4574-B7BD-A486C85B06C3/data/Containers/Data/Application/FFE5A297-770F-418D-9331-5833B1CCA94C/Documents/1588911030406.txt due to access control checks.
[Error] TypeError: Origin http://192.168.15.26:6789 is not allowed by Access-Control-Allow-Origin.
  capacitorConsole (user-script:2:78)
  (anonymous function) (bundle.js:4179)
  promiseReactionJob

@imhoffd imhoffd changed the title fix(ios): Support CORS when using HMR fix(ios): Support CORS when using Live Reload Jun 30, 2020
@imhoffd
Copy link
Contributor

imhoffd commented Jun 30, 2020

@diachedelic Thanks for the PR! We are going to address this in Capacitor 3 using something like this: #3180

@realityfilter
Copy link

As this is not addressed in Capacitor 3. Can this pull request be merged to be aligned with the android implementation?

@diachedelic
Copy link
Contributor Author

@realityfilter PR #3433 supersedes this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants