Skip to content

Commit

Permalink
perf(projects): env config
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Nov 19, 2023
1 parent 8e41a8f commit 0742326
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build/config/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions env.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -24,7 +24,7 @@ export function createServiceConfig(env: Env.ImportMeta) {
demo: 'http://localhost:9530'
}
}
} satisfies App.Service.ServiceConfigMap;
};

const { VITE_SERVICE_ENV = 'dev' } = env;

Expand All @@ -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';
}
Expand Down
9 changes: 7 additions & 2 deletions src/typings/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,18 +523,23 @@ declare namespace App {
*/
type EnvType = 'dev' | 'test' | 'prod';

/**
* other baseURL key
*/
type OtherBaseURLKey = 'demo';

/**
* the backend service config
*/
interface ServiceConfig {
interface ServiceConfig<T extends OtherBaseURLKey = OtherBaseURLKey> {
/**
* the backend service base url
*/
baseURL: string;
/**
* other backend service base url map
*/
otherBaseURL: Record<string, string>;
otherBaseURL: Record<T, string>;
}

/**
Expand Down

0 comments on commit 0742326

Please sign in to comment.