Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support work over remote config
- Loading branch information
1 parent
7266606
commit 9d4c133
Showing
9 changed files
with
111 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import { INgxRemoteConfig } from 'ngx-remote-config'; | ||
|
||
export interface IEnvironment { | ||
server: boolean; | ||
type: 'prod' | 'development'; | ||
production: boolean; | ||
apiUrl: string; | ||
remoteConfig?: INgxRemoteConfig; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
libs/rucken/ionic/src/lib/utils/ngx-remote-config.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Inject, Injectable } from '@angular/core'; | ||
import { HTTP } from '@ionic-native/http/ngx'; | ||
import { Platform } from '@ionic/angular'; | ||
import { INgxRemoteConfig, NgxRemoteConfigService, NGX_REMOTE_CONFIG } from 'ngx-remote-config'; | ||
|
||
@Injectable() | ||
export class NgxRemoteConfigIonicService<T = any> extends NgxRemoteConfigService { | ||
constructor( | ||
private http: HTTP, | ||
private platform: Platform, | ||
@Inject(NGX_REMOTE_CONFIG) private options: INgxRemoteConfig, | ||
private httpClient: HttpClient | ||
) { | ||
super( | ||
options, | ||
httpClient | ||
); | ||
} | ||
initConfigAsync() { | ||
if (this.platform.is('cordova')) { | ||
return new Promise(resolve => | ||
this.http.disableRedirect(false).then(result => | ||
this.http.get(this.options.url, {}, {}).then( | ||
response => { | ||
let config: T; | ||
try { | ||
config = JSON.parse(response.data); | ||
} catch (error) { | ||
config = response.data; | ||
} | ||
this.config$.next(config || {}); | ||
resolve(config); | ||
}, | ||
response => { | ||
const config: T = this.options.default || {}; | ||
this.config$.next(config); | ||
resolve(config); | ||
} | ||
) | ||
) | ||
); | ||
} | ||
return super.initConfigAsync(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters