ionic-team / ionic-team/cordova-plugin-ionic-webview
Never enforce CORS like UIWebView do
- Dominant language
- Objective-C
- Stars
- 493
- Forks
- 410
- PR merge metrics
- No merged PRs in 30d
Description
I'v read https://ionicframework.com/docs/wkwebview/#cors
```
Unfortunately there’s no API to disable this
```
But any chance to implement it? I see there is local `http://localhost:8080` server which handles `file://` URLs but there is no XHR polyfill for http(s) URLs. Is there any plan to implement iOS native proxy for all http(s) XHR on the same local webserver? The proxy will respond with `access-control-request-headers` and the CORS issue will be solved.
I made a simple proxy on nodejs, see the proxy http-proxy handler code below which solves the issue:
```
onProxyRes(proxyRes, req, res) {
let allowedOrigin = false;
if (req.headers.origin) {
proxyRes.headers['access-control-allow-origin'] = '*';
proxyRes.headers['access-control-allow-credentials'] = 'true';
allowedOrigin = true;
}
if (req.headers['access-control-request-method']) {
proxyRes.headers['access-control-allow-methods'] = req.headers['access-control-request-method'];
}
if (req.headers['access-control-request-headers']) {
proxyRes.headers['access-control-allow-headers'] = req.headers['access-control-request-headers'];
}
if (allowedOrigin) {
if (req.method === 'OPTIONS') {
proxyRes.statusCode = 200;
}
}
}
```
Any chance to port it into the native part of `cordova-plugin-ionic-webview` ?
Contributor guide
Assessment
This issue has not been assessed yet.