Updated DevStore to work automatically

This commit is contained in:
2024-02-15 13:40:27 +01:00
parent 7d5c5fc1fa
commit 93a3ab41bd
2 changed files with 23 additions and 39 deletions

View File

@ -1,21 +1,29 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { map } from 'rxjs/operators';
interface DevelopmentStoreState {
baseUrl: string;
}
@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class DevelopmentStore {
private state: BehaviorSubject<DevelopmentStoreState> = new BehaviorSubject<DevelopmentStoreState>({
baseUrl: 'http://localhost/',
});
/**
* THIS IS NOT A OBSERVABLE STORE.
* This store automatically identifies if the env is production or development.
* If this app is running on development mode, it will add port 80 to the base url.
*/
export class EnvironmentService {
private isDevelopment: boolean;
constructor() {
this.isDevelopment = location.port === '4200';
}
get baseUrl() {
return this.state.asObservable().pipe(map(state => state.baseUrl));
getIsDevelopment(): boolean {
return this.isDevelopment;
}
getBaseUrl(): string {
if (this.isDevelopment) {
return 'http://localhost:80/';
} else {
return window.location.origin;
}
}
}