Browse Source

add develop configs

dev
powersir 1 year ago
parent
commit
9ccb01006f
6 changed files with 39 additions and 33 deletions
  1. +1
    -4
      .env.develop
  2. +1
    -4
      .env.production
  3. +30
    -0
      src/hooks/use-global-settings/index.ts
  4. +5
    -1
      src/request/index.ts
  5. +1
    -23
      src/utils/env.ts
  6. +1
    -1
      vite.config.ts

+ 1
- 4
.env.develop View File

@@ -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=

+ 1
- 4
.env.production View File

@@ -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


+ 30
- 0
src/hooks/use-global-settings/index.ts View File

@@ -0,0 +1,30 @@
import type { GlobConfig } from '/#/config';

import { warn } from '@/utils/log';
import { getAppEnvConfig } from '@/utils/env';

export const useGlobSetting = (): Readonly<GlobConfig> => {
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<GlobConfig> = {
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<GlobConfig>;
};

+ 5
- 1
src/request/index.ts View File

@@ -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<T> = Promise<[boolean, T, AxiosResponse<T>]>;
@@ -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;

+ 1
- 23
src/utils/env.ts View File

@@ -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;
}

+ 1
- 1
vite.config.ts View File

@@ -25,7 +25,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
},
},
server: {
https: true,
https: false,
host: true,
port: VITE_PORT,
},


Loading…
Cancel
Save