Updated DevStore to work automatically

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

View File

@ -1,27 +1,3 @@
# Frontend
# Befor production deployment
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 17.0.3.
## Development server
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files.
## Code scaffolding
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
## Build
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory.
## Running unit tests
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
## Running end-to-end tests
Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.
## Further help
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
Note that the baseURL is automatically defined by the `DevelopementStore.ts` store.

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;
}
}
}