Skip to content

Commit

Permalink
Initialize the client with the fake host for Lite server (#8935)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Aug 14, 2024
1 parent 15a690f commit f6b2b97
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changeset/flat-meals-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@gradio/app": minor
"@gradio/wasm": minor
"gradio": minor
---

feat:Initialize the client with the fake host for Lite server
3 changes: 2 additions & 1 deletion js/app/src/lite/LiteIndex.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -181,7 +182,7 @@
<Index
space={null}
src={null}
host={null}
host={FAKE_LITE_HOST}
{info}
{container}
{is_embed}
Expand Down
6 changes: 5 additions & 1 deletion js/wasm/network/host.ts
Original file line number Diff line number Diff line change
@@ -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
);
}

0 comments on commit f6b2b97

Please sign in to comment.