Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple add base url support #1635

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
dinhlongviolin1 marked this conversation as resolved.
Show resolved Hide resolved
}
}

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 = () => {
dinhlongviolin1 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading