Skip to content

Commit

Permalink
fix: api请求挂起
Browse files Browse the repository at this point in the history
  • Loading branch information
piccaSun committed Jul 10, 2024
1 parent 802ac98 commit 2a04422
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions apps/mis-web/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import "antd/dist/reset.css";

import { failEvent } from "@ddadaal/next-typed-api-routes-runtime/lib/client";
import { ClusterConfigSchema, SimpleClusterSchema } from "@scow/config/build/cluster";
import { ClusterRuntimeInfo } from "@scow/config/build/type";
import { UiExtensionStore } from "@scow/lib-web/build/extensions/UiExtensionStore";
import { DarkModeCookie, DarkModeProvider, getDarkModeCookieValue } from "@scow/lib-web/build/layouts/darkMode";
import { GlobalStyle } from "@scow/lib-web/build/layouts/globalStyle";
Expand Down Expand Up @@ -231,6 +232,7 @@ MyApp.getInitialProps = async (appContext: AppContext) => {

const token = USE_MOCK ? "123" : getTokenFromCookie(appContext.ctx);

let clustersRuntimeInfo: { results: ClusterRuntimeInfo[] } = { results: []};
if (token) {
// Why not directly call validateToken but create an api?
// Because this method will (in next.js's perspective) be called both in client and server,
Expand All @@ -253,23 +255,24 @@ MyApp.getInitialProps = async (appContext: AppContext) => {
if (clusterConfigs && Object.keys(clusterConfigs).length > 0) {
extra.clusterConfigs = clusterConfigs;
}

clustersRuntimeInfo = await api.getClustersRuntimeInfo({ query: { token } })
.then((x) => x, () => ({ results: []}));
}
}

const clustersRuntimeInfo = await api.getClustersRuntimeInfo({ query: { token } }).then((x) => x, () => undefined);

// get deployed clusters' simple info (only clusterId, displayName and priority)
const simpleClustersInfo
= await api.getSimpleClustersInfoFromConfigFiles({}).then((x) => x, () => ({ clustersInfo: {} }));

extra.initialSimpleClustersInfo = simpleClustersInfo?.clustersInfo;
extra.initialSimpleClustersInfo = simpleClustersInfo?.clustersInfo ?? {};

const publicConfigClusters = extra.clusterConfigs && Object.keys(extra.clusterConfigs).length > 0 ?
getPublicConfigClusters(extra.clusterConfigs) : getPublicConfigClusters(extra.initialSimpleClustersInfo) ?? {};

const activatedClusters
= formatActivatedClusters({
clustersRuntimeInfo: clustersRuntimeInfo?.results,
clustersRuntimeInfo: clustersRuntimeInfo.results,
misConfigClusters: publicConfigClusters });

extra.initialActivatedClusters = activatedClusters.misActivatedClusters ?? {};
Expand Down

0 comments on commit 2a04422

Please sign in to comment.