From 27bd4581d402cd14f12b062f180230315a84752b Mon Sep 17 00:00:00 2001 From: cv5ch <176032962+cv5ch@users.noreply.github.com> Date: Mon, 1 Sep 2025 17:25:55 +0200 Subject: [PATCH] Removed config.json, Backend URL is now always loaded via environment's "prodAPIEndpoint" --- .../core/_services/shared/config.service.ts | 54 +++++-------------- src/assets/config.json.example | 3 -- 2 files changed, 12 insertions(+), 45 deletions(-) delete mode 100644 src/assets/config.json.example diff --git a/src/app/core/_services/shared/config.service.ts b/src/app/core/_services/shared/config.service.ts index a0eef6328..0eb9facdc 100644 --- a/src/app/core/_services/shared/config.service.ts +++ b/src/app/core/_services/shared/config.service.ts @@ -1,53 +1,23 @@ -import { HttpClient } from '@angular/common/http'; -import { Injectable } from '@angular/core'; -import { Observable } from 'rxjs'; import { environment } from 'src/environments/environment'; +import { Injectable } from '@angular/core'; + @Injectable({ providedIn: 'root' }) export class ConfigService { - private configUrl = 'assets/config.json'; - constructor(private http: HttpClient) { } + /** + * Get the API endpoint from the environment configuration + * @returns {string} The API endpoint URL + */ + public getEndpoint(): string { + let apiEndpoint = environment.config.prodApiEndpoint; - private getConfigOnce(): Observable { - return this.http.get(this.configUrl); - } - - public refreshEndpoint(){ - let ApiEndPoint = ""; - this.getConfigOnce().subscribe(config => { - // Assuming the JSON contains a property named 'backendUrl' - if (config && config.hashtopolis_backend_url) { - // If we get a config from the backend, we set the config property - ApiEndPoint = config.hashtopolis_backend_url; - // Remove trailing slash, because this causing invalid URLs - if (ApiEndPoint.endsWith('/')) { - ApiEndPoint = ApiEndPoint.slice(0, -1); - } - localStorage.setItem('prodApiEndpoint', ApiEndPoint); - } else if (config && !config.hashtopolis_backend_url) { - console.error('Invalid configuration file. Please check your config.json. Using defaults.'); - ApiEndPoint = environment.config.prodApiEndpoint; - localStorage.setItem('prodApiEndpoint', ApiEndPoint); - } else { - ApiEndPoint = environment.config.prodApiEndpoint; - localStorage.setItem('prodApiEndpoint', ApiEndPoint); - } - }, - error => { - ApiEndPoint = environment.config.prodApiEndpoint; - localStorage.setItem('prodApiEndpoint', ApiEndPoint); + // Remove trailing slash for URL consistency + if (apiEndpoint.endsWith('/')) { + apiEndpoint = apiEndpoint.slice(0, -1); } - ); - } - public getEndpoint(){ - let ApiEndPoint = localStorage.getItem('prodApiEndpoint'); - if (!ApiEndPoint) { - this.refreshEndpoint(); - } - ApiEndPoint = localStorage.getItem('prodApiEndpoint'); - return ApiEndPoint; + return apiEndpoint; } } diff --git a/src/assets/config.json.example b/src/assets/config.json.example deleted file mode 100644 index d4247d37d..000000000 --- a/src/assets/config.json.example +++ /dev/null @@ -1,3 +0,0 @@ -{ - "hashtopolis_backend_url": "${HASHTOPOLIS_BACKEND_URL}" -}