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: 42 additions & 12 deletions src/app/core/_services/shared/config.service.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,53 @@
import { environment } from 'src/environments/environment';

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

Check failure on line 2 in src/app/core/_services/shared/config.service.ts

View workflow job for this annotation

GitHub Actions / Lint & Prettier Check

There should be at least one empty line between import groups
import { Observable } from 'rxjs';

Check failure on line 3 in src/app/core/_services/shared/config.service.ts

View workflow job for this annotation

GitHub Actions / Lint & Prettier Check

`rxjs` import should occur before import of `@angular/common/http`
import { environment } from 'src/environments/environment';

Check failure on line 4 in src/app/core/_services/shared/config.service.ts

View workflow job for this annotation

GitHub Actions / Lint & Prettier Check

`src/environments/environment` import should occur before import of `@angular/common/http`

@Injectable({
providedIn: 'root'
})
export class ConfigService {
/**
* Get the API endpoint from the environment configuration
* @returns {string} The API endpoint URL
*/
public getEndpoint(): string {
let apiEndpoint = environment.config.prodApiEndpoint;
private configUrl = 'assets/config.json';
constructor(private http: HttpClient) { }

Check failure on line 11 in src/app/core/_services/shared/config.service.ts

View workflow job for this annotation

GitHub Actions / Lint & Prettier Check

Delete `·`

// Remove trailing slash for URL consistency
if (apiEndpoint.endsWith('/')) {
apiEndpoint = apiEndpoint.slice(0, -1);
private getConfigOnce(): Observable<any> {

Check failure on line 13 in src/app/core/_services/shared/config.service.ts

View workflow job for this annotation

GitHub Actions / Lint & Prettier Check

Unexpected any. Specify a different type
return this.http.get(this.configUrl);
}

public refreshEndpoint(){

Check failure on line 17 in src/app/core/_services/shared/config.service.ts

View workflow job for this annotation

GitHub Actions / Lint & Prettier Check

Insert `·`
let ApiEndPoint = "";

Check failure on line 18 in src/app/core/_services/shared/config.service.ts

View workflow job for this annotation

GitHub Actions / Lint & Prettier Check

Replace `""` with `''`
this.getConfigOnce().subscribe(config => {

Check failure on line 19 in src/app/core/_services/shared/config.service.ts

View workflow job for this annotation

GitHub Actions / Lint & Prettier Check

Replace `config` with `⏎······(config)`
// Assuming the JSON contains a property named 'backendUrl'

Check failure on line 20 in src/app/core/_services/shared/config.service.ts

View workflow job for this annotation

GitHub Actions / Lint & Prettier Check

Replace `······` with `········`
if (config && config.hashtopolis_backend_url) {

Check failure on line 21 in src/app/core/_services/shared/config.service.ts

View workflow job for this annotation

GitHub Actions / Lint & Prettier Check

Insert `··`
// 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);
}
);
}

return apiEndpoint;
public getEndpoint(){
let ApiEndPoint = localStorage.getItem('prodApiEndpoint');
if (!ApiEndPoint) {
this.refreshEndpoint();
}
ApiEndPoint = localStorage.getItem('prodApiEndpoint');
return ApiEndPoint;
}
}
3 changes: 3 additions & 0 deletions src/assets/config.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"hashtopolis_backend_url": "${HASHTOPOLIS_BACKEND_URL}"
}