Skip to content

Commit 9548b35

Browse files
authored
fix(web) : add origin and host to globalStore (#839)
1 parent ecf2a64 commit 9548b35

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

web/src/apis/typing.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export type TApplication = {
1919
tls: boolean;
2020
develop_token: string;
2121
port: number;
22+
host: string;
23+
origin: string;
2224
};
2325

2426
export type TBundle = {

web/src/components/Editor/typesResolve/index.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ import useGlobalStore from "@/pages/globalStore";
77

88
async function loadPackageTypings(packageName: string) {
99
const { currentApp } = useGlobalStore.getState();
10-
const port = currentApp?.port;
1110

12-
let url = `//${currentApp?.domain?.domain}`;
13-
if (port !== 80 && port !== 443) {
14-
url = `${url}:${port}`;
15-
}
11+
const url = `//${currentApp?.host}`;
1612

1713
const res = await axios({
1814
url: `${url}/_/typing/package?packageName=${packageName}`,

web/src/pages/app/functions/store.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,9 @@ const useFunctionStore = create<State>()(
3232

3333
if (!currentFunctionName) return "";
3434

35-
const protocol = currentApp?.tls ? "https://" : "http://";
36-
const port = currentApp?.port;
35+
const origin = currentApp?.origin;
3736

38-
let host = currentApp?.domain?.domain;
39-
if (port !== 80 && port !== 443) {
40-
host = `${host}:${port}`;
41-
}
42-
43-
return `${protocol}${host}/${currentFunctionName}`;
37+
return `${origin}/${currentFunctionName}`;
4438
},
4539

4640
setCurrentRequestId: (requestId) => {

web/src/pages/globalStore.ts

+14
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ const useGlobalStore = create<State>()(
9797
localStorage.setItem("app", app.appid);
9898
set((state) => {
9999
state.currentApp = app;
100+
101+
if (typeof state.currentApp === "object") {
102+
const protocol = state.currentApp?.tls ? "https://" : "http://";
103+
const domain = state.currentApp?.domain?.domain;
104+
const port = state.currentApp?.port;
105+
106+
if (port === 80 || port === 443) {
107+
state.currentApp.host = domain;
108+
} else {
109+
state.currentApp.host = `${domain}:${port}`;
110+
}
111+
112+
state.currentApp.origin = protocol + state.currentApp.host;
113+
}
100114
});
101115
},
102116

0 commit comments

Comments
 (0)