Skip to content

Commit 599fb8b

Browse files
routing/navigation relative to subpath
1 parent 6b7f01c commit 599fb8b

File tree

7 files changed

+24
-9
lines changed

7 files changed

+24
-9
lines changed

client/packages/lowcoder/src/constants/apiConstants.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,18 @@ export const API_REQUEST_HEADERS: RawAxiosRequestHeaders = {
5252
"Content-Type": "application/json",
5353
};
5454

55-
export const SERVER_HOST = `${REACT_APP_API_SERVICE_URL ?? ""}/__LOWCODER_BASEPATH_PLACEHOLDER__`;
55+
const nodeEnv = process.env.NODE_ENV ?? "development";
56+
const isDev = nodeEnv === "development";
57+
const DEV_SERVER_HOST = `${REACT_APP_API_SERVICE_URL ?? ""}/`;
58+
const PROD_SERVER_HOST = `${REACT_APP_API_SERVICE_URL ?? ""}/__LOWCODER_BASEPATH_PLACEHOLDER__`;
59+
60+
const createUrlByEnv = (baseUrl: string = "") => {
61+
const nodeEnv = process.env.NODE_ENV ?? "development";
62+
const isDev = nodeEnv === "development";
63+
return isDev ? `${baseUrl}/` : `${baseUrl}/__LOWCODER_BASEPATH_PLACEHOLDER__`;
64+
}
65+
66+
export const SERVER_HOST = createUrlByEnv(REACT_APP_API_SERVICE_URL);
5667
export const ASSETS_URI = (id: string) => `${SERVER_HOST}/api/v1/assets/${id}`;
5768
export const USER_HEAD_UPLOAD_URL = `${SERVER_HOST}/api/v1/users/photo`;
5869
export const ORG_ICON_UPLOAD_URL = (orgId: string) => `${SERVER_HOST}/api/v1/organizations/${orgId}/logo`;
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// export const SERVER_HOST = `${REACT_APP_NODE_SERVICE_URL ?? ""}`;
22
// export const NPM_REGISTRY_URL = `${SERVER_HOST}/node-service/api/npm/registry`;
33
// export const NPM_PLUGIN_ASSETS_BASE_URL = `${SERVER_HOST}/node-service/api/npm/package`;
4+
5+
import { SERVER_HOST } from "./apiConstants";
6+
47
export const ASSETS_BASE_URL = `api/npm/package`;
5-
export const SERVER_HOST = `${REACT_APP_API_SERVICE_URL ?? ""}`;
68
export const NPM_REGISTRY_URL = `${SERVER_HOST}/api/npm/registry`;
79
export const NPM_PLUGIN_ASSETS_BASE_URL = `${SERVER_HOST}/api/npm/package`;

client/packages/lowcoder/src/pages/setting/subscriptions/subscriptionCancel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function SubscriptionCancel() {
4343
const session_id = query.get("session_id");
4444

4545
useEffect(() => {
46-
window.location.replace(SUBSCRIPTION_SETTING);
46+
history.replace(SUBSCRIPTION_SETTING);
4747
}, []);
4848

4949
return (

client/packages/lowcoder/src/pages/userAuth/authUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ export function authRespValidate(
8383
if (doValidResponse(resp)) {
8484
onAuthSuccess?.();
8585
sessionStorage.setItem("_just_logged_in_", "true");
86-
history.replace(replaceUrl.replace(baseUrl, ''));
86+
window.location.replace(replaceUrl.replace(baseUrl, ''));
8787
} else if (
8888
resp.data.code === SERVER_ERROR_CODES.EXCEED_MAX_USER_ORG_COUNT ||
8989
resp.data.code === SERVER_ERROR_CODES.ALREADY_IN_ORGANIZATION
9090
) {
9191
messageInstance.error(resp.data.message);
9292
// redirect after displaying the message for a second
93-
setTimeout(() => window.location.replace(replaceUrl), 1500);
93+
setTimeout(() => history.replace(replaceUrl), 1500);
9494
} else {
9595
throw Error(resp.data.message);
9696
}

client/packages/lowcoder/src/redux/sagas/orgSagas.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { User } from "constants/userConstants";
3333
import { getUserSaga } from "redux/sagas/userSagas";
3434
import { GetMyOrgsResponse } from "@lowcoder-ee/api/userApi";
3535
import UserApi from "@lowcoder-ee/api/userApi";
36+
import history from "@lowcoder-ee/util/history";
3637

3738
export function* updateGroupSaga(action: ReduxAction<UpdateGroupActionPayload>) {
3839
try {
@@ -248,7 +249,7 @@ export function* switchOrgSaga(action: ReduxAction<{ orgId: string }>) {
248249
const response: AxiosResponse<ApiResponse> = yield call(OrgApi.switchOrg, action.payload.orgId);
249250
const isValidResponse: boolean = validateResponse(response);
250251
if (isValidResponse) {
251-
window.location.replace(BASE_URL);
252+
history.replace(BASE_URL);
252253
}
253254
} catch (error: any) {
254255
messageInstance.error(error.message);

client/packages/lowcoder/src/redux/sagas/userSagas.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { AuthSearchParams } from "constants/authConstants";
2626
import { saveAuthSearchParams } from "pages/userAuth/authUtils";
2727
import { initTranslator } from "i18n";
2828
import { fetchWorkspacesAction } from "../reduxActions/orgActions";
29+
import history from "@lowcoder-ee/util/history";
2930

3031
function validResponseData(response: AxiosResponse<ApiResponse>) {
3132
return response && response.data && response.data.data;
@@ -45,7 +46,7 @@ export function* getUserSaga() {
4546
const redirectUrl = new URL(redirectUri);
4647
redirectUrl.pathname = currentUrl.pathname;
4748
redirectUrl.search = currentUrl.search;
48-
window.location.replace(redirectUrl);
49+
history.replace(redirectUrl);
4950
return;
5051
}
5152
if (validateResponse(response)) {
@@ -163,7 +164,7 @@ export function* logoutSaga(action: LogoutActionType) {
163164
if (isValidResponse) {
164165
yield put(logoutSuccess());
165166
localStorage.clear();
166-
window.location.replace(redirectURL);
167+
history.replace(redirectURL);
167168
}
168169
} catch (error) {
169170
log.error(error);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
import { createBrowserHistory } from "history";
2-
export default createBrowserHistory({basename: "__LOWCODER_BASEPATH_PLACEHOLDER__"});
2+
export default createBrowserHistory({basename: "/__LOWCODER_BASEPATH_PLACEHOLDER__"});

0 commit comments

Comments
 (0)