forked from labring/sealos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getInitData.ts
50 lines (43 loc) · 1.46 KB
/
getInitData.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@/services/backend/response';
import type { FormSliderListType } from '@/types';
import { readFileSync } from 'fs';
import { noGpuSliderKey } from '@/constants/app';
export type Response = {
SEALOS_DOMAIN: string;
DOMAIN_PORT: string;
INGRESS_SECRET: string;
SHOW_EVENT_ANALYZE: boolean;
FORM_SLIDER_LIST_CONFIG: FormSliderListType;
};
export const defaultVal = {
[noGpuSliderKey]: {
cpu: [100, 200, 500, 1000, 2000, 3000, 4000, 8000],
memory: [64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384]
}
};
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
if (!global.FormSliderListConfig) {
const filename =
process.env.NODE_ENV === 'development'
? 'data/form_slider_config.json.local'
: '/app/data/form_slider_config.json';
const res = JSON.parse(readFileSync(filename, 'utf-8'));
console.log(res);
global.FormSliderListConfig = res;
}
} catch (error) {
console.log(error);
global.FormSliderListConfig = defaultVal;
}
jsonRes<Response>(res, {
data: {
SEALOS_DOMAIN: process.env.SEALOS_DOMAIN || 'cloud.sealos.io',
DOMAIN_PORT: process.env.DOMAIN_PORT || '',
INGRESS_SECRET: process.env.INGRESS_SECRET || 'wildcard-cert',
SHOW_EVENT_ANALYZE: !!process.env.FASTGPT_KEY,
FORM_SLIDER_LIST_CONFIG: global.FormSliderListConfig
}
});
}