ionic-native-http-connection-backend
Version:
A solution to CORS problem with Ionic and WKWebView
40 lines • 2.04 kB
JavaScript
import { Injectable } from '@angular/core';
import { checkAvailability } from '@awesome-cordova-plugins/core';
import { from } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { checkExternalRequest } from './utils/check-external-request';
import * as i0 from "@angular/core";
import * as i1 from "@ionic/angular";
import * as i2 from "./native-http-backend";
import * as i3 from "@angular/common/http";
var NativeHttpFallback = /** @class */ (function () {
function NativeHttpFallback(platform, cordovaHttpBackend, fallbackBackend) {
this.platform = platform;
this.cordovaHttpBackend = cordovaHttpBackend;
this.fallbackBackend = fallbackBackend;
}
NativeHttpFallback.prototype.handle = function (req) {
var _this = this;
return from(this.platform.ready()).pipe(switchMap(function () {
/**
* Native HTTP Cordova plugin doesn't like local requests
*/
var isExternalRequest = checkExternalRequest(req);
if (isExternalRequest &&
checkAvailability('cordova.plugin.http') === true) {
return _this.cordovaHttpBackend.handle(req);
}
else {
return _this.fallbackBackend.handle(req);
}
}));
};
NativeHttpFallback.ɵfac = function NativeHttpFallback_Factory(t) { return new (t || NativeHttpFallback)(i0.ɵɵinject(i1.Platform), i0.ɵɵinject(i2.NativeHttpBackend), i0.ɵɵinject(i3.HttpBackend)); };
NativeHttpFallback.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: NativeHttpFallback, factory: NativeHttpFallback.ɵfac });
return NativeHttpFallback;
}());
export { NativeHttpFallback };
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(NativeHttpFallback, [{
type: Injectable
}], function () { return [{ type: i1.Platform }, { type: i2.NativeHttpBackend }, { type: i3.HttpBackend }]; }, null); })();
//# sourceMappingURL=native-http-fallback.js.map