diff --git a/.env.develop b/.env.develop index bc9cd6f..1d3fa18 100644 --- a/.env.develop +++ b/.env.develop @@ -1,6 +1,3 @@ -# Whether to open mock -VITE_USE_MOCK = false - # public path VITE_PUBLIC_PATH = / @@ -11,7 +8,7 @@ VITE_DROP_CONSOLE = false VITE_GLOB_API_URL = https://test.vogocm.com:9697 # File upload address, optional -VITE_GLOB_UPLOAD_URL=/upload +VITE_GLOB_UPLOAD_URL = https://test.vogocm.com:9697/admin-api/infra/upload # Interface prefix VITE_GLOB_API_URL_PREFIX= diff --git a/.env.production b/.env.production index ddaf273..a55f0c3 100644 --- a/.env.production +++ b/.env.production @@ -1,6 +1,3 @@ -# Whether to open mock -VITE_USE_MOCK = false - # public path VITE_PUBLIC_PATH = / @@ -16,7 +13,7 @@ VITE_BUILD_COMPRESS = 'none' VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE = false # Basic interface address SPA -VITE_GLOB_API_URL= +VITE_GLOB_API_URL = https://test.vogocm.com:9697 # File upload address, optional # It can be forwarded by nginx or write the actual address directly diff --git a/src/hooks/use-global-settings/index.ts b/src/hooks/use-global-settings/index.ts new file mode 100644 index 0000000..9ce0fa4 --- /dev/null +++ b/src/hooks/use-global-settings/index.ts @@ -0,0 +1,30 @@ +import type { GlobConfig } from '/#/config'; + +import { warn } from '@/utils/log'; +import { getAppEnvConfig } from '@/utils/env'; + +export const useGlobSetting = (): Readonly => { + const { + VITE_GLOB_APP_TITLE, + VITE_GLOB_API_URL, + VITE_GLOB_APP_SHORT_NAME, + VITE_GLOB_API_URL_PREFIX, + VITE_GLOB_UPLOAD_URL, + } = getAppEnvConfig(); + + if (!/[a-zA-Z\_]*/.test(VITE_GLOB_APP_SHORT_NAME)) { + warn( + `VITE_GLOB_APP_SHORT_NAME Variables can only be characters/underscores, please modify in the environment variables and re-running.`, + ); + } + + // Take global configuration + const glob: Readonly = { + title: VITE_GLOB_APP_TITLE, + apiUrl: VITE_GLOB_API_URL, + shortName: VITE_GLOB_APP_SHORT_NAME, + urlPrefix: VITE_GLOB_API_URL_PREFIX, + uploadUrl: VITE_GLOB_UPLOAD_URL, + }; + return glob as Readonly; +}; diff --git a/src/request/index.ts b/src/request/index.ts index 007e253..15c7de5 100644 --- a/src/request/index.ts +++ b/src/request/index.ts @@ -7,6 +7,10 @@ import axios, { } from 'axios'; import {antdUtils} from '@/utils/antd'; +import { useGlobSetting } from '@/hooks/use-global-settings'; + +const { apiUrl = '' } = useGlobSetting(); + // axios.defaults.withCredentials = true; export type Response = Promise<[boolean, T, AxiosResponse]>; @@ -151,6 +155,6 @@ class Request { } } -const request = new Request({timeout: 60 * 1000 * 5, baseURL: 'https://test.vogocm.com:9697'}); +const request = new Request({timeout: 60 * 1000 * 5, baseURL: apiUrl}); export default request; diff --git a/src/utils/env.ts b/src/utils/env.ts index 9423a7a..4acc7dc 100644 --- a/src/utils/env.ts +++ b/src/utils/env.ts @@ -16,7 +16,7 @@ export function getStorageShortName() { export function getAppEnvConfig() { const ENV_NAME = getConfigFileName(import.meta.env); - + const ENV = (import.meta.env.DEV ? // Get the global configuration (the configuration will be extracted independently when packaging) (import.meta.env as unknown as GlobEnvConfig) @@ -45,39 +45,17 @@ export function getAppEnvConfig() { }; } -/** - * @description: Development mode - */ export const devMode = 'development'; - -/** - * @description: Production mode - */ export const prodMode = 'production'; -/** - * @description: Get environment variables - * @returns: - * @example: - */ export function getEnv(): string { return import.meta.env.MODE; } -/** - * @description: Is it a development mode - * @returns: - * @example: - */ export function isDevMode(): boolean { return import.meta.env.DEV; } -/** - * @description: Is it a production mode - * @returns: - * @example: - */ export function isProdMode(): boolean { return import.meta.env.PROD; } diff --git a/vite.config.ts b/vite.config.ts index 57b9a23..8cacf7d 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -25,7 +25,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { }, }, server: { - https: true, + https: false, host: true, port: VITE_PORT, },