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 81e4c11
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions apps/mis-web/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,14 @@ MyApp.getInitialProps = async (appContext: AppContext) => {
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
5 changes: 4 additions & 1 deletion apps/mis-web/src/pages/api/admin/getClustersRuntimeInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export const GetClustersRuntimeInfoSchema = typeboxRouteSchema({
200: Type.Object({
results: Type.Array(ClusterRuntimeInfoSchema),
}),

403: Type.Null(),
},
});

Expand All @@ -46,11 +48,12 @@ export default route(GetClustersRuntimeInfoSchema,

// if not initialized, every one can get clustersRuntimeInfo
if (await queryIfInitialized()) {

const { token } = req.query;
// when firstly used in getInitialProps, check the token
// when logged in, use auth()
const info = token ? await validateToken(token) : await auth(req, res);
if (!info) { return; }
if (!info) { return { 403: null }; }
}

const client = getClient(ConfigServiceClient);
Expand Down
4 changes: 3 additions & 1 deletion apps/mis-web/src/pages/api/simpleClustersInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export const GetSimpleClustersInfoFromConfigFilesSchema = typeboxRouteSchema({

200: Type.Object({
clustersInfo: Type.Record(Type.String(), SimpleClusterSchema) }),

403: Type.Null(),
},
});

Expand All @@ -47,7 +49,7 @@ export default route(GetSimpleClustersInfoFromConfigFilesSchema,
// if not initialized, every one can getSimpleClusterInfo which includes clusterId, displayedName and priority
if (await queryIfInitialized()) {
const info = await auth(req, res);
if (!info) { return; }
if (!info) { return { 403: null }; }
}

const clustersFullInfo: Record<string, ClusterConfigSchema> = await getClusterConfigFiles();
Expand Down

0 comments on commit 81e4c11

Please sign in to comment.