Log a warning in the UI when falling back to default connection parameters

This commit is contained in:
Alexandr Stelnykovych
2025-05-20 12:56:24 +03:00
parent 8035c3d5ac
commit 58ca3150e7
4 changed files with 22 additions and 21 deletions

View File

@@ -43,8 +43,13 @@ export interface AuthKeyResponse {
export class MetaAPI {
constructor(
private http: HttpClient,
@Inject(PORTMASTER_HTTP_API_ENDPOINT) @Optional() private httpEndpoint: string = 'http://127.0.0.1:817/api',
) { }
@Inject(PORTMASTER_HTTP_API_ENDPOINT) @Optional() private httpEndpoint: string,
) {
if (!this.httpEndpoint) {
this.httpEndpoint = `http://localhost:817/api`;
console.warn("[portmaster-api: MetaAPI] No HTTP API endpoint provided, using default: " + this.httpEndpoint);
}
}
listEndpoints(): Observable<MetaEndpoint[]> {
return this.http.get<MetaEndpoint[]>(`${this.httpEndpoint}/v1/endpoints`)

View File

@@ -47,11 +47,13 @@ export class PortmasterAPIModule {
* @param cfg The module configuration defining the Portmaster HTTP and Websocket API endpoints.
*/
static forRoot(cfg: ModuleConfig = {}): ModuleWithProviders<PortmasterAPIModule> {
if (cfg.httpAPI === undefined) {
cfg.httpAPI = `http://127.0.0.1:817/api`;
if (!cfg.httpAPI) {
cfg.httpAPI = `http://${window.location.host}/api`;
console.warn("[portmaster-api] No HTTP API endpoint provided, using default: " + cfg.httpAPI);
}
if (cfg.websocketAPI === undefined) {
cfg.websocketAPI = `ws://127.0.0.1:817/api/database/v1`;
if (!cfg.websocketAPI) {
cfg.websocketAPI = `ws://${window.location.host}/api/database/v1`;
console.warn("[portmaster-api] No WebSocket API endpoint provided, using default: " + cfg.websocketAPI);
}
return {