From 1bac3b78d7b866ace11e396a66088d92036282fe Mon Sep 17 00:00:00 2001 From: Soybean Date: Mon, 20 Nov 2023 21:32:55 +0800 Subject: [PATCH] perf(projects): env config --- build/config/proxy.ts | 2 +- env.config.ts | 6 +++--- src/typings/app.d.ts | 9 +++++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/build/config/proxy.ts b/build/config/proxy.ts index edc7ce04..91f27079 100644 --- a/build/config/proxy.ts +++ b/build/config/proxy.ts @@ -25,7 +25,7 @@ export function createViteProxy(env: Env.ImportMeta) { const otherURLEntries = Object.entries(otherBaseURL); for (const [key, url] of otherURLEntries) { - const proxyPattern = createProxyPattern(key); + const proxyPattern = createProxyPattern(key as App.Service.OtherBaseURLKey); proxy[proxyPattern] = { target: url, diff --git a/env.config.ts b/env.config.ts index 3ee2abd6..b4abc2b4 100644 --- a/env.config.ts +++ b/env.config.ts @@ -5,7 +5,7 @@ export function createServiceConfig(env: Env.ImportMeta) { const mockURL = 'https://mock.apifox.com/m1/3109515-0-default'; - const serviceConfigMap = { + const serviceConfigMap: App.Service.ServiceConfigMap = { dev: { baseURL: mockURL, otherBaseURL: { @@ -24,7 +24,7 @@ export function createServiceConfig(env: Env.ImportMeta) { demo: 'http://localhost:9530' } } - } satisfies App.Service.ServiceConfigMap; + }; const { VITE_SERVICE_ENV = 'dev' } = env; @@ -35,7 +35,7 @@ export function createServiceConfig(env: Env.ImportMeta) { * get proxy pattern of service url * @param key if not set, will use the default key */ -export function createProxyPattern(key?: string) { +export function createProxyPattern(key?: App.Service.OtherBaseURLKey) { if (!key) { return '/proxy'; } diff --git a/src/typings/app.d.ts b/src/typings/app.d.ts index 30e2d9b2..7fa61dda 100644 --- a/src/typings/app.d.ts +++ b/src/typings/app.d.ts @@ -523,10 +523,15 @@ declare namespace App { */ type EnvType = 'dev' | 'test' | 'prod'; + /** + * other baseURL key + */ + type OtherBaseURLKey = 'demo'; + /** * the backend service config */ - interface ServiceConfig { + interface ServiceConfig { /** * the backend service base url */ @@ -534,7 +539,7 @@ declare namespace App { /** * other backend service base url map */ - otherBaseURL: Record; + otherBaseURL: Record; } /**