Initialize the client with the fake host for Lite server (#8935)

* Initialize the client with the fake host for Lite server

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: pngwn <hello@pngwn.io>
This commit is contained in:
Yuichiro Tachibana (Tsuchiya) 2024-08-14 15:50:16 +09:00 committed by GitHub
parent 15a690fa96
commit f6b2b97d47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 2 deletions

View File

@ -0,0 +1,7 @@
---
"@gradio/app": minor
"@gradio/wasm": minor
"gradio": minor
---
feat:Initialize the client with the fake host for Lite server

View File

@ -10,6 +10,7 @@
import ErrorDisplay from "./ErrorDisplay.svelte";
import type { ThemeMode } from "../types";
import { WorkerProxy, type WorkerProxyOptions } from "@gradio/wasm";
import { FAKE_LITE_HOST } from "@gradio/wasm/network";
import { Client } from "@gradio/client";
import { wasm_proxied_fetch } from "./fetch";
import { wasm_proxied_stream_factory } from "./sse";
@ -181,7 +182,7 @@
<Index
space={null}
src={null}
host={null}
host={FAKE_LITE_HOST}
{info}
{container}
{is_embed}

View File

@ -1,8 +1,12 @@
// A special hostname representing the Lite's server.
// For example, when the endpoint is a local file (`file:/*`), the host name is set to this value (ref: determine_protocol() in client/js/src/helpers/init_helpers.ts)
export const FAKE_LITE_HOST = "lite.local";
export function is_self_host(url: URL): boolean {
return (
url.host === window.location.host ||
url.host === "localhost:7860" ||
url.host === "127.0.0.1:7860" || // Ref: https://github.com/gradio-app/gradio/blob/v3.32.0/js/app/src/Index.svelte#L194
url.host === "lite.local" // A special hostname set when the endpoint is a local file (`file:/*`). See `determine_protocol()` in `client/js/src/utils.ts`
url.host === FAKE_LITE_HOST
);
}