-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): adding AppConfig service
to load remote overlay config and featureFlags
- Loading branch information
Showing
17 changed files
with
201 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
# Add files here to ignore them from prettier formatting | ||
*.js | ||
*.js.map | ||
*.d.ts | ||
*.md | ||
*.min.* | ||
|
||
/dist | ||
/coverage |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# TODO | ||
|
||
1. [feature flags](https://www.bennadel.com/blog/3709-loading-and-using-remote-feature-flags-in-angular-9-0-0-next-12.htm) |
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,8 @@ | ||
{ | ||
"DOCS_BASE_URL": "http://sumo.com/docs", | ||
"featureFlags": { | ||
"feature-a": true, | ||
"feature-b": false, | ||
"feature-c": true | ||
} | ||
} |
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,13 @@ | ||
import * as packageJson from '../../../../package.json'; | ||
|
||
const base = document.querySelector('base'); | ||
|
||
export default { | ||
appName: 'YETI', | ||
secret: 'SECRET', | ||
apiToken: 'SECRET_TOKEN', | ||
baseUrl: (base && base.href) || window.location.origin + '/', | ||
versions: { | ||
app: packageJson.version | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// import { OidcProviderConfig } from '@ngx-starter-kit/oidc'; | ||
import { ModuleWithProviders } from '@angular/core'; | ||
|
||
export type LogLevel = 'debug' | 'info' | 'warn' | 'error'; | ||
|
||
export interface IEnvironment { | ||
production: boolean; | ||
envName: string; | ||
REMOTE_CONFIG_URL: string; | ||
|
||
// Enables use of ng.profiler.timeChangeDetection(); in browser console | ||
enableDebugTools?: boolean; | ||
logLevel?: LogLevel; | ||
|
||
[key: string]: any; | ||
plugins: ModuleWithProviders<any>[]; | ||
featureFlags?: { | ||
[key: string]: boolean; | ||
}; | ||
} |
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,3 +1,5 @@ | ||
export * from './lib/core.module'; | ||
export { AnalyticsService } from './lib/services/analytics.service'; | ||
export { LayoutService } from './lib/services/layout.service'; | ||
export { AppConfigService } from './lib/services/app-config.service'; | ||
export { PageTitleService } from './lib/services/page-title.service'; |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,45 @@ | ||
import { | ||
HttpErrorResponse, | ||
HttpEvent, | ||
HttpHandler, | ||
HttpInterceptor, | ||
HttpRequest | ||
} from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { Observable, throwError } from 'rxjs'; | ||
import { catchError } from 'rxjs/operators'; | ||
// import { Store } from '@ngxs/store'; | ||
// import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class ErrorInterceptor implements HttpInterceptor { | ||
|
||
constructor(/*private snackBar: MatSnackBar, private store : Store*/) {} | ||
|
||
intercept( | ||
req: HttpRequest<any>, | ||
next: HttpHandler | ||
): Observable<HttpEvent<any>> { | ||
return next.handle(req).pipe(catchError(this.handleError)); | ||
} | ||
|
||
/* tslint:disable */ | ||
public handleError = (errorRes: HttpErrorResponse) => { | ||
const { | ||
error: { status, error, message } | ||
} = errorRes; | ||
// Do messaging and error handling here | ||
// this.snackBar.open( | ||
// `Error ! ${message}`, | ||
// '', | ||
// ErrorInterceptor.snackBarConfig | ||
// ); | ||
console.error( | ||
`Backend Error ! status: ${status}, error: ${error}, message: ${message}` | ||
); | ||
|
||
return throwError(errorRes); | ||
}; | ||
} |
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,32 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Injectable } from '@angular/core'; | ||
import { environment } from '@env/environment'; | ||
import { IEnvironment } from '@env/ienvironment'; | ||
|
||
/** | ||
* In Components, inject `AppConfigService` and usage: | ||
* this.isShowingFeatureA = appConfig.config.featureFlags[ 'feature-a' ]; | ||
*/ | ||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class AppConfigService { | ||
private configUrl = environment.REMOTE_CONFIG_URL; | ||
private configPrivate = environment; | ||
|
||
constructor(private http: HttpClient) {} | ||
|
||
async load(configUrl = this.configUrl) { | ||
try { | ||
const remoteConfig = await this.http | ||
.get<IEnvironment>(configUrl) | ||
.toPromise(); | ||
this.configPrivate = { ...environment, ...remoteConfig }; | ||
} catch { | ||
console.error(`Unable to load remote config url ${configUrl}`); | ||
} | ||
} | ||
get config() { | ||
return this.configPrivate; | ||
} | ||
} |