Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 12 additions & 42 deletions src/app/core/_services/shared/config.service.ts
Original file line number Diff line number Diff line change
@@ -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<any> {
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;
}
}
3 changes: 0 additions & 3 deletions src/assets/config.json.example

This file was deleted.