forked from nativescript-community/https
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathns-https.module.ts
More file actions
40 lines (38 loc) · 1.86 KB
/
ns-https.module.ts
File metadata and controls
40 lines (38 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { NgModule, ModuleWithProviders, Optional, Inject, InjectionToken } from '@angular/core';
import { HttpBackend } from '@angular/common/http';
import { NativeScriptHttpClientModule } from '@nativescript/angular';
import { HttpsSSLPinningOptions, enableSSLPinning } from '@nativescript-community/https';
import { HTTPS_REQUEST_DEFAULT_OPTIONS, NativeScriptHttpXhrBackend, HttpsRequestDefaultOptions } from './ns-http-xhr-backend';
import { ExcludedService } from './excluded.service';
/** Page size injection token. */
export const HTTPS_SSL_PINNING_OPTIONS = new InjectionToken<HttpsSSLPinningOptions>('HTTPS_SSL_PINNING_OPTIONS');
@NgModule({
providers: [
ExcludedService,
NativeScriptHttpXhrBackend,
{ provide: HttpBackend, useExisting: NativeScriptHttpXhrBackend },
{ provide: HTTPS_REQUEST_DEFAULT_OPTIONS, useValue: {} },
{ provide: HTTPS_SSL_PINNING_OPTIONS, useValue: { host: '', certificate: '' } }
],
imports: [NativeScriptHttpClientModule],
exports: [NativeScriptHttpClientModule]
})
export class NativeScriptHttpsModule {
constructor(@Optional()@Inject(HTTPS_SSL_PINNING_OPTIONS) defaults?: HttpsSSLPinningOptions) {
enableSSLPinning(defaults ?? { host: '', certificate: '' });
}
/**
* Creates and configures a module.
* @param defaults Https request default options.
* @returns A wrapper around an NgModule that associates it with the providers.
*/
static forRoot(defaults: HttpsRequestDefaultOptions & HttpsSSLPinningOptions = { host: '', certificate: '' }): ModuleWithProviders<NativeScriptHttpsModule> {
return {
ngModule: NativeScriptHttpsModule,
providers: [
{ provide: HTTPS_REQUEST_DEFAULT_OPTIONS, useValue: defaults },
{ provide: HTTPS_SSL_PINNING_OPTIONS, useValue: defaults }
]
};
}
}