Refactor environment variables.

This commit is contained in:
Spencer Ofwiti 2021-03-16 18:32:26 +03:00
parent 03be46e169
commit 124a6bf295
4 changed files with 19 additions and 22 deletions

View File

@ -8,6 +8,7 @@ import {
import {Observable, throwError} from 'rxjs'; import {Observable, throwError} from 'rxjs';
import {catchError} from 'rxjs/operators'; import {catchError} from 'rxjs/operators';
import {ErrorDialogService} from '@app/_services'; import {ErrorDialogService} from '@app/_services';
import {environment} from '@src/environments/environment';
@Injectable() @Injectable()
export class ErrorInterceptor implements HttpInterceptor { export class ErrorInterceptor implements HttpInterceptor {
@ -16,10 +17,12 @@ export class ErrorInterceptor implements HttpInterceptor {
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> { intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
return next.handle(request).pipe(catchError((err: HttpErrorResponse) => { return next.handle(request).pipe(catchError((err: HttpErrorResponse) => {
if (!environment.production) {
this.errorDialogService.openDialog({ this.errorDialogService.openDialog({
message: err.error.message || err.statusText, message: err.error.message || err.statusText || 'Unknown Error',
status: err.status status: err.status || 0
}); });
}
if ([401, 403].indexOf(err.status) !== -1) { if ([401, 403].indexOf(err.status) !== -1) {
location.reload(true); location.reload(true);
} }

View File

@ -37,7 +37,7 @@ export class AuthService {
getWithToken(): void { getWithToken(): void {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.responseType = 'text'; xhr.responseType = 'text';
xhr.open('GET', environment.cicAuthUrl + window.location.search.substring(1)); xhr.open('GET', environment.cicMetaUrl + window.location.search.substring(1));
xhr.setRequestHeader('Authorization', 'Bearer ' + this.sessionToken); xhr.setRequestHeader('Authorization', 'Bearer ' + this.sessionToken);
xhr.setRequestHeader('Content-Type', 'application/json'); xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('x-cic-automerge', 'none'); xhr.setRequestHeader('x-cic-automerge', 'none');
@ -55,7 +55,7 @@ export class AuthService {
sendResponse(hobaResponseEncoded): void { sendResponse(hobaResponseEncoded): void {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.responseType = 'text'; xhr.responseType = 'text';
xhr.open('GET', environment.cicAuthUrl + window.location.search.substring(1)); xhr.open('GET', environment.cicMetaUrl + window.location.search.substring(1));
xhr.setRequestHeader('Authorization', 'HOBA ' + hobaResponseEncoded); xhr.setRequestHeader('Authorization', 'HOBA ' + hobaResponseEncoded);
xhr.setRequestHeader('Content-Type', 'application/json'); xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('x-cic-automerge', 'none'); xhr.setRequestHeader('x-cic-automerge', 'none');
@ -75,7 +75,7 @@ export class AuthService {
getChallenge(): void { getChallenge(): void {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
xhr.responseType = 'arraybuffer'; xhr.responseType = 'arraybuffer';
xhr.open('GET', environment.cicAuthUrl + window.location.search.substring(1)); xhr.open('GET', environment.cicMetaUrl + window.location.search.substring(1));
xhr.onload = (e) => { xhr.onload = (e) => {
if (xhr.status === 401) { if (xhr.status === 401) {
const authHeader = xhr.getResponseHeader('WWW-Authenticate'); const authHeader = xhr.getResponseHeader('WWW-Authenticate');
@ -107,7 +107,7 @@ export class AuthService {
async loginResponse(o): Promise<any> { async loginResponse(o): Promise<any> {
const r = await signChallenge(o.challenge, o.realm, environment.cicAuthUrl, this.mutableKeyStore); const r = await signChallenge(o.challenge, o.realm, environment.cicMetaUrl, this.mutableKeyStore);
this.sendResponse(r); this.sendResponse(r);
} }

View File

@ -6,14 +6,11 @@ export const environment = {
level: NgxLoggerLevel.OFF, level: NgxLoggerLevel.OFF,
serverLogLevel: NgxLoggerLevel.ERROR, serverLogLevel: NgxLoggerLevel.ERROR,
loggingUrl: 'http://localhost:8000', loggingUrl: 'http://localhost:8000',
cicAuthUrl: 'https://meta.dev.grassrootseconomics.net:80', cicMetaUrl: 'https://meta.grassrootseconomics.net',
cicMetaUrl: 'http://localhost:63380',
publicKeysUrl: 'http://localhost:8000/keys.asc', publicKeysUrl: 'http://localhost:8000/keys.asc',
cicCacheUrl: 'http://localhost:63313', cicCacheUrl: 'https://cache.grassrootseconomics.net',
cicScriptsUrl: 'http://localhost:9999',
web3Provider: 'ws://localhost:63546', web3Provider: 'ws://localhost:63546',
cicUssdUrl: 'http://localhost:63315', cicUssdUrl: 'https://ussd.grassrootseconomics.net',
cicEthUrl: 'http://localhost:63314',
registryAddress: '0x6Ca3cB14aA6F761712E1C18646AfBA4d5Ae249E8', registryAddress: '0x6Ca3cB14aA6F761712E1C18646AfBA4d5Ae249E8',
trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C' trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C'
}; };

View File

@ -8,16 +8,13 @@ export const environment = {
production: false, production: false,
bloxbergChainId: 8996, bloxbergChainId: 8996,
level: NgxLoggerLevel.TRACE, level: NgxLoggerLevel.TRACE,
serverLogLevel: NgxLoggerLevel.ERROR, serverLogLevel: NgxLoggerLevel.OFF,
loggingUrl: 'http://localhost:8000', loggingUrl: 'http://localhost:8000',
cicAuthUrl: 'https://meta.dev.grassrootseconomics.net:80', cicMetaUrl: 'https://meta.dev.grassrootseconomics.net',
cicMetaUrl: 'http://localhost:63380',
publicKeysUrl: 'http://localhost:8000/keys.asc', publicKeysUrl: 'http://localhost:8000/keys.asc',
cicCacheUrl: 'http://localhost:63313', cicCacheUrl: 'https://cache.dev.grassrootseconomics.net',
cicScriptsUrl: 'http://localhost:9999', web3Provider: 'ws://localhost:8548',
web3Provider: 'ws://localhost:63546', cicUssdUrl: 'https://ussd.dev.grassrootseconomics.net',
cicUssdUrl: 'http://localhost:63315',
cicEthUrl: 'http://localhost:63314',
registryAddress: '0x6Ca3cB14aA6F761712E1C18646AfBA4d5Ae249E8', registryAddress: '0x6Ca3cB14aA6F761712E1C18646AfBA4d5Ae249E8',
trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C' trustedDeclaratorAddress: '0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C'
}; };