fix: force UI to use IPv4 (127.0.0.1) for API endpoints

Previously, the API endpoint was defined using `localhost`, which could resolve to the IPv6 address `::1`.
This caused issues because the Portmaster core service is listening on `127.0.0.1:817` and only fast-tracking connections to that specific IPv4 address.
This commit is contained in:
Alexandr Stelnykovych
2025-05-16 10:56:30 +03:00
parent b2e47e40ff
commit 5bc1e779b2
5 changed files with 10 additions and 10 deletions

View File

@@ -43,7 +43,7 @@ export interface AuthKeyResponse {
export class MetaAPI {
constructor(
private http: HttpClient,
@Inject(PORTMASTER_HTTP_API_ENDPOINT) @Optional() private httpEndpoint: string = 'http://localhost:817/api',
@Inject(PORTMASTER_HTTP_API_ENDPOINT) @Optional() private httpEndpoint: string = 'http://127.0.0.1:817/api',
) { }
listEndpoints(): Observable<MetaEndpoint[]> {

View File

@@ -48,10 +48,10 @@ export class PortmasterAPIModule {
*/
static forRoot(cfg: ModuleConfig = {}): ModuleWithProviders<PortmasterAPIModule> {
if (cfg.httpAPI === undefined) {
cfg.httpAPI = `http://${window.location.host}/api`;
cfg.httpAPI = `http://127.0.0.1:817/api`;
}
if (cfg.websocketAPI === undefined) {
cfg.websocketAPI = `ws://${window.location.host}/api/database/v1`;
cfg.websocketAPI = `ws://127.0.0.1:817/api/database/v1`;
}
return {

View File

@@ -80,8 +80,8 @@ if (location.pathname !== "/prompt") {
providers: [
provideHttpClient(),
importProvidersFrom(PortmasterAPIModule.forRoot({
websocketAPI: "ws://localhost:817/api/database/v1",
httpAPI: "http://localhost:817/api"
websocketAPI: "ws://127.0.0.1:817/api/database/v1",
httpAPI: "http://127.0.0.1:817/api"
})),
NotificationsService,
{

View File

@@ -8,7 +8,7 @@
],
"remote": {
"urls": [
"http://localhost:817"
"http://127.0.0.1:817"
]
},
"permissions": [

View File

@@ -181,15 +181,15 @@ pub fn may_navigate_to_ui(win: &mut WebviewWindow, force: bool) {
// Only for dev build
// Allow connection to http://localhost:4200
let capabilities = include_str!("../capabilities/default.json")
.replace("http://localhost:817", "http://localhost:4200");
.replace("http://127.0.0.1:817", "http://127.0.0.1:4200");
let _ = win.add_capability(capabilities);
debug!("[tauri] navigating to http://localhost:4200");
_ = win.navigate("http://localhost:4200".parse().unwrap());
debug!("[tauri] navigating to http://127.0.0.1:4200");
_ = win.navigate("http://127.0.0.1:4200".parse().unwrap());
}
#[cfg(not(debug_assertions))]
{
_ = win.navigate("http://localhost:817".parse().unwrap());
_ = win.navigate("http://127.0.0.1:817".parse().unwrap());
}
} else {
error!(