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: 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()