working test deploy config
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { APP_INITIALIZER, InjectionToken } from '@angular/core';
|
||||
import { lastValueFrom } from 'rxjs';
|
||||
|
||||
export interface AppConfig {
|
||||
apiBaseUrl: string;
|
||||
}
|
||||
|
||||
export const APP_CONFIG = new InjectionToken<AppConfig>('appConfig');
|
||||
|
||||
const _appConfig: AppConfig = {
|
||||
apiBaseUrl: '',
|
||||
};
|
||||
|
||||
export function appConfigFactory(http: HttpClient) {
|
||||
return (): Promise<void> => {
|
||||
return lastValueFrom(http.get<AppConfig>('./config.json')).then(
|
||||
(config) => {
|
||||
Object.assign(_appConfig, config);
|
||||
},
|
||||
() => {
|
||||
// Keep defaults if config.json is not available (dev mode).
|
||||
},
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export const appConfigProvider = {
|
||||
provide: APP_CONFIG,
|
||||
useValue: _appConfig,
|
||||
};
|
||||
|
||||
export const appConfigInitProvider = {
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: appConfigFactory,
|
||||
deps: [HttpClient],
|
||||
multi: true,
|
||||
};
|
||||
|
||||
export function getAppConfig(): AppConfig {
|
||||
return _appConfig;
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { Injectable, inject } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { BehaviorSubject, firstValueFrom, map, Observable, tap } from 'rxjs';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
import { getAppConfig } from './app-config.service';
|
||||
import { AppUser, AuthTokenResponse } from '../interfaces/auth';
|
||||
|
||||
const TOKEN_KEY = 'kmtn_access_token';
|
||||
@@ -12,7 +12,7 @@ const TOKEN_KEY = 'kmtn_access_token';
|
||||
})
|
||||
export class AuthService {
|
||||
private http = inject(HttpClient);
|
||||
private baseUrl = `${environment.apiBaseUrl}/api/auth`;
|
||||
private baseUrl = `${getAppConfig().apiBaseUrl}/api/auth`;
|
||||
|
||||
private authStateSubject = new BehaviorSubject<AppUser | null>(null);
|
||||
|
||||
|
||||
@@ -2,15 +2,15 @@ import { Injectable, inject } from '@angular/core';
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
import { Event } from '../interfaces/event';
|
||||
import { getAppConfig } from './app-config.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class EventService {
|
||||
private http = inject(HttpClient);
|
||||
private baseUrl = `${environment.apiBaseUrl}/api/events`;
|
||||
private baseUrl = `${getAppConfig().apiBaseUrl}/api/events`;
|
||||
|
||||
/** Fetch events, optionally filtered by active status. */
|
||||
getEvents(active?: boolean): Observable<Event[]> {
|
||||
|
||||
@@ -2,15 +2,15 @@ import { Injectable, inject } from '@angular/core';
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
import { Program } from '../interfaces/program';
|
||||
import { getAppConfig } from './app-config.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ProgramService {
|
||||
private http = inject(HttpClient);
|
||||
private baseUrl = `${environment.apiBaseUrl}/api/programs`;
|
||||
private baseUrl = `${getAppConfig().apiBaseUrl}/api/programs`;
|
||||
|
||||
/** Fetch all programs, optionally filtered by day_of_week (1=Mon … 7=Sun). */
|
||||
getPrograms(day?: number): Observable<Program[]> {
|
||||
|
||||
@@ -2,15 +2,15 @@ import { Injectable, inject } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
import { Tier } from '../interfaces/tier';
|
||||
import { getAppConfig } from './app-config.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class TierService {
|
||||
private http = inject(HttpClient);
|
||||
private baseUrl = `${environment.apiBaseUrl}/api/tiers`;
|
||||
private baseUrl = `${getAppConfig().apiBaseUrl}/api/tiers`;
|
||||
|
||||
/** Fetch all tiers ordered by display_order. */
|
||||
getTiers(): Observable<Tier[]> {
|
||||
|
||||
Reference in New Issue
Block a user