Skip to content

Commit

Permalink
Decouple add base url support (#1635)
Browse files Browse the repository at this point in the history
* add base url support

* fix tests
  • Loading branch information
dinhlongviolin1 authored Aug 5, 2024
1 parent 1ad66d6 commit 98660d8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions frontend/taipy-gui/base/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) => {
Expand Down
3 changes: 3 additions & 0 deletions frontend/taipy-gui/base/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const getBase = () => {
return document.getElementsByTagName("base")[0].getAttribute("href");
};
2 changes: 1 addition & 1 deletion taipy/gui/custom/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion taipy/gui/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions taipy/gui/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 98660d8

Please sign in to comment.