Updated DevStore to work automatically
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user