feat: remote config auth

This commit is contained in:
DIYgod 2024-04-02 21:39:50 +08:00
parent ab77defb07
commit 7a4cd377de
No known key found for this signature in database
1 changed files with 15 additions and 9 deletions

View File

@ -633,21 +633,27 @@ const calculateValue = () => {
};
calculateValue();
if (envs.REMOTE_CONFIG) {
ofetch(envs.REMOTE_CONFIG)
.then(async (data) => {
(async () => {
if (envs.REMOTE_CONFIG) {
const { default: logger } = await import('@/utils/logger');
try {
const data = await ofetch(envs.REMOTE_CONFIG, {
headers: {
Authorization: `Basic ${envs.REMOTE_CONFIG_AUTH}`,
},
});
if (data) {
envs = Object.assign(envs, data);
calculateValue();
const { default: logger } = await import('@/utils/logger');
logger.info('Remote config loaded.');
} else {
logger.error('Remote config load failed.');
}
})
.catch(async (error) => {
const { default: logger } = await import('@/utils/logger');
} catch (error) {
logger.error('Remote config load failed.', error);
});
}
}
}
})();
// @ts-expect-error value is set
export const config: Config = value;