• Stars
    star
    160
  • Rank 234,703 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A solution to CORS issues with Ionic and iOS

ionic-native-http-connection-backend

version MIT License

This library adds @awesome-cordova-plugins/http (when available) as a connection backend to Angular's Http and HttpClient

Motivation

Now that Apple promotes/requires the use of WKWebView instead of the deprecated UIWebView, Ionic has switched newly created apps over via their cordova-plugin-ionic-webview (and Cordova offers it via their cordova-plugin-wkwebview-engine). That causes requests that used to work just fine to fail with CORS errors.

The real solution of course is to fix the CORS issues server side - but this may not be possible with e.g. 3rd party APIs.

Even though there is a way to solve CORS issues without changing server's response header by using @awesome-cordova-plugins/http, this only works on device and doesn't provide all the power of Angular's Http and HttpClient.

How it works

  • The library provides a HttpBackend interface for Angular's HttpClient
  • This HttpBackend interface tries to use @awesome-cordova-plugins/http whenever it is possible (= on device with installed plugin)
  • If HttpBackend finds it impossible to use @awesome-cordova-plugins/http, it falls back to standard Angular code (HttpXhrBackend, which uses XmlHttpRequest)

This strategy allows developers to use Angular's HttpClient transparently in both environments: Browser and Device.

Installation

npm install --save ionic-native-http-connection-backend

Then follow instructions at https://ionicframework.com/docs/native/http/#installation

Usage

Add NativeHttpModule, NativeHttpBackend and NativeHttpFallback into the application's module

import { NgModule } from '@angular/core';
import { HttpBackend, HttpXhrBackend } from '@angular/common/http';
import { NativeHttpModule, NativeHttpBackend, NativeHttpFallback } from 'ionic-native-http-connection-backend';
import { Platform } from '@ionic/angular';

@NgModule({
    declarations: [],
    imports: [
        NativeHttpModule
    ],
    bootstrap: [],
    entryComponents: [],
    providers: [
        {provide: HttpBackend, useClass: NativeHttpFallback, deps: [Platform, NativeHttpBackend, HttpXhrBackend]},
    ],
})
export class AppModule {
}

Contributing

Contributing guidelines could be found in CONTRIBUTING.md

Troubleshooting

TROUBLESHOOTING.md

More Repositories

1

img-comparison-slider

Image comparison slider. Compare images before and after. Supports React, Vue, Angular.
TypeScript
527
star
2

cv-template

Manage your CV as a web app (HTML, JS, CSS). Automatically generate HTML and PDF versions and deploy them on GitHub Pages on every push.
JavaScript
138
star
3

component-library

An easy way to create HTML styleguide for existing web project
JavaScript
41
star
4

react-nested-routes-example

🌳 An example of a well-crafted React app with nested routes and breadcrumbs
JavaScript
21
star
5

passwordmeter

Password security checker function based on http://www.passwordmeter.com/. Unobtrusive and tested.
JavaScript
8
star
6

green-blocker

🐠 Chrome extension to temporarily block distracting websites in a polite, loving way.
TypeScript
3
star
7

rx-game

TypeScript
2
star
8

cv

HTML
2
star
9

x-ray

Display HTML/Web component and show/hide it's code
TypeScript
2
star
10

habrahabr

Пример использования стайлгада, основанный на компонентах сайта Хабрахабр.ру
HTML
1
star
11

react-event-param

Pass custom param to event handler. Avoid binding.
TypeScript
1
star
12

cordova-HTTP2

Deprecated! cordovaHTTP with postJSON, PUT and DELETE methods
Objective-C
1
star
13

blog

Fully automated blog powered by Git, Gatsby, CircleCI, and GitHub Pages
JavaScript
1
star
14

lifehacks

A list of one-sentence lifehacks helping me to be happier in the moment
1
star
15

web-component-typescript-starter

Web Component with Typescript, SASS, and Webpack. This is the best example on GitHub, really.
TypeScript
1
star
16

sensus

🟢 AI sensor for your GitHub comments
TypeScript
1
star