From 383b6253c6c7cd8e71e71459e7000bb33e150242 Mon Sep 17 00:00:00 2001 From: dinhlongviolin1 Date: Mon, 5 Aug 2024 18:54:54 +0700 Subject: [PATCH 1/2] add base url support --- frontend/taipy-gui/base/src/app.ts | 9 +++++++-- frontend/taipy-gui/base/src/utils.ts | 3 +++ taipy/gui/custom/_page.py | 2 +- taipy/gui/server.py | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 frontend/taipy-gui/base/src/utils.ts diff --git a/frontend/taipy-gui/base/src/app.ts b/frontend/taipy-gui/base/src/app.ts index 1ed6578267..f484232634 100644 --- a/frontend/taipy-gui/base/src/app.ts +++ b/frontend/taipy-gui/base/src/app.ts @@ -7,6 +7,7 @@ import { DataManager, ModuleData } from "./dataManager"; import { initSocket } from "./socket"; import { TaipyWsAdapter, WsAdapter } from "./wsAdapter"; import { WsMessageType } from "../../src/context/wsUtils"; +import { getBase } from "./utils"; export type OnInitHandler = (taipyApp: TaipyApp) => void; export type OnChangeHandler = (taipyApp: TaipyApp, encodedName: string, value: unknown) => void; @@ -46,9 +47,9 @@ export class TaipyApp { onInit: OnInitHandler | undefined = undefined, onChange: OnChangeHandler | undefined = undefined, path: string | undefined = undefined, - socket: Socket | undefined = undefined + socket: Socket | undefined = undefined, ) { - socket = socket || io("/", { autoConnect: false }); + socket = socket || io("/", { autoConnect: false, path: `${getBase()}socket.io` }); this.onInit = onInit; this.onChange = onChange; this.variableData = undefined; @@ -252,6 +253,10 @@ export class TaipyApp { getWsStatus() { return this._ackList; } + + getBaseUrl() { + return getBase(); + } } export const createApp = (onInit?: OnInitHandler, onChange?: OnChangeHandler, path?: string, socket?: Socket) => { diff --git a/frontend/taipy-gui/base/src/utils.ts b/frontend/taipy-gui/base/src/utils.ts new file mode 100644 index 0000000000..b4f48dfdaf --- /dev/null +++ b/frontend/taipy-gui/base/src/utils.ts @@ -0,0 +1,3 @@ +export const getBase = () => { + return document.getElementsByTagName("base")[0].getAttribute("href"); +}; diff --git a/taipy/gui/custom/_page.py b/taipy/gui/custom/_page.py index f23837e53c..048e6b165e 100644 --- a/taipy/gui/custom/_page.py +++ b/taipy/gui/custom/_page.py @@ -55,7 +55,7 @@ def get_id(self) -> str: return self.rh_id if self.rh_id != "" else str(id(self)) @abstractmethod - def get_resources(self, path: str, taipy_resource_path: str) -> t.Any: + def get_resources(self, path: str, taipy_resource_path: str, base_url: str) -> t.Any: raise NotImplementedError diff --git a/taipy/gui/server.py b/taipy/gui/server.py index e6493731fc..58e79b5fbf 100644 --- a/taipy/gui/server.py +++ b/taipy/gui/server.py @@ -161,7 +161,7 @@ def my_index(path): if resource_handler is None: return (f"Invalid value for query {_Server._RESOURCE_HANDLER_ARG}", 404) try: - return resource_handler.get_resources(path, static_folder) + return resource_handler.get_resources(path, static_folder, base_url) except Exception as e: raise RuntimeError("Can't get resources from custom resource handler") from e if path == "" or path == "index.html" or "." not in path: From 58cf5905781d2fb68c0850ab327dd0908a8458d9 Mon Sep 17 00:00:00 2001 From: dinhlongviolin1 Date: Tue, 6 Aug 2024 00:52:25 +0700 Subject: [PATCH 2/2] fix tests --- taipy/gui/state.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/taipy/gui/state.py b/taipy/gui/state.py index b60122e227..dc0e7124c7 100644 --- a/taipy/gui/state.py +++ b/taipy/gui/state.py @@ -117,6 +117,8 @@ def __filter_var_list(var_list: t.Iterable[str], excluded_attrs: t.Iterable[str] return filter(lambda n: n not in excluded_attrs, var_list) def __getattribute__(self, name: str) -> t.Any: + if name == "__class__": + return State if name in State.__methods: return super().__getattribute__(name) gui: "Gui" = self.get_gui()