waveterm/frontend/util/fetchutil.ts
Evan Simkowitz b51ff834b2
Happy new year! (#1684)
Update all 2024 references to 2025
2025-01-04 20:56:57 -08:00

23 lines
607 B
TypeScript

// Copyright 2025, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
// Utility to abstract the fetch function so the Electron net module can be used when available.
let net: Electron.Net;
if (typeof window === "undefined") {
try {
import("electron").then(({ net: electronNet }) => (net = electronNet));
} catch (e) {
// do nothing
}
}
export function fetch(input: string | GlobalRequest | URL, init?: RequestInit): Promise<Response> {
if (net) {
return net.fetch(input.toString(), init);
} else {
return globalThis.fetch(input, init);
}
}