perf(projects): env config

This commit is contained in:
Soybean 2023-11-20 21:32:55 +08:00
parent 8081e19ebc
commit 1bac3b78d7
3 changed files with 11 additions and 6 deletions

View File

@ -25,7 +25,7 @@ export function createViteProxy(env: Env.ImportMeta) {
const otherURLEntries = Object.entries(otherBaseURL); const otherURLEntries = Object.entries(otherBaseURL);
for (const [key, url] of otherURLEntries) { for (const [key, url] of otherURLEntries) {
const proxyPattern = createProxyPattern(key); const proxyPattern = createProxyPattern(key as App.Service.OtherBaseURLKey);
proxy[proxyPattern] = { proxy[proxyPattern] = {
target: url, target: url,

View File

@ -5,7 +5,7 @@
export function createServiceConfig(env: Env.ImportMeta) { export function createServiceConfig(env: Env.ImportMeta) {
const mockURL = 'https://mock.apifox.com/m1/3109515-0-default'; const mockURL = 'https://mock.apifox.com/m1/3109515-0-default';
const serviceConfigMap = { const serviceConfigMap: App.Service.ServiceConfigMap = {
dev: { dev: {
baseURL: mockURL, baseURL: mockURL,
otherBaseURL: { otherBaseURL: {
@ -24,7 +24,7 @@ export function createServiceConfig(env: Env.ImportMeta) {
demo: 'http://localhost:9530' demo: 'http://localhost:9530'
} }
} }
} satisfies App.Service.ServiceConfigMap; };
const { VITE_SERVICE_ENV = 'dev' } = env; const { VITE_SERVICE_ENV = 'dev' } = env;
@ -35,7 +35,7 @@ export function createServiceConfig(env: Env.ImportMeta) {
* get proxy pattern of service url * get proxy pattern of service url
* @param key if not set, will use the default key * @param key if not set, will use the default key
*/ */
export function createProxyPattern(key?: string) { export function createProxyPattern(key?: App.Service.OtherBaseURLKey) {
if (!key) { if (!key) {
return '/proxy'; return '/proxy';
} }

View File

@ -523,10 +523,15 @@ declare namespace App {
*/ */
type EnvType = 'dev' | 'test' | 'prod'; type EnvType = 'dev' | 'test' | 'prod';
/**
* other baseURL key
*/
type OtherBaseURLKey = 'demo';
/** /**
* the backend service config * the backend service config
*/ */
interface ServiceConfig { interface ServiceConfig<T extends OtherBaseURLKey = OtherBaseURLKey> {
/** /**
* the backend service base url * the backend service base url
*/ */
@ -534,7 +539,7 @@ declare namespace App {
/** /**
* other backend service base url map * other backend service base url map
*/ */
otherBaseURL: Record<string, string>; otherBaseURL: Record<T, string>;
} }
/** /**