fix: getUmiConfig
This commit is contained in:
parent
0f38997ffa
commit
06de43da39
@ -1,7 +1,9 @@
|
||||
import { getUmiConfig } from '@nocobase/utils/umiConfig';
|
||||
import dotenv from 'dotenv';
|
||||
import { resolve } from 'path';
|
||||
import { defineConfig } from 'umi';
|
||||
import { getUmiConfig } from '../../core/utils/src/umiConfig';
|
||||
|
||||
const umiConfig = getUmiConfig();
|
||||
|
||||
dotenv.config({
|
||||
path: resolve(__dirname, '../../../.env'),
|
||||
@ -9,8 +11,6 @@ dotenv.config({
|
||||
|
||||
process.env.MFSU_AD = 'none';
|
||||
|
||||
const umiConfig = getUmiConfig();
|
||||
|
||||
export default defineConfig({
|
||||
hash: true,
|
||||
define: {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { getUmiConfig } from '@nocobase/utils';
|
||||
import { getUmiConfig } from '@nocobase/utils/umiConfig';
|
||||
import dotenv from 'dotenv';
|
||||
import { resolve } from 'path';
|
||||
import { defineConfig } from 'umi';
|
||||
|
17
packages/core/utils/umiConfig.d.ts
vendored
Normal file
17
packages/core/utils/umiConfig.d.ts
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
export declare function getUmiConfig(): {
|
||||
define: {
|
||||
'process.env.SERVER_BASE_URL': string;
|
||||
};
|
||||
proxy: {
|
||||
[x: string]: {
|
||||
target: string;
|
||||
changeOrigin: boolean;
|
||||
} | {
|
||||
target: string;
|
||||
changeOrigin: boolean;
|
||||
pathRewrite: {
|
||||
[x: string]: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
38
packages/core/utils/umiConfig.js
Normal file
38
packages/core/utils/umiConfig.js
Normal file
@ -0,0 +1,38 @@
|
||||
function getUmiConfig() {
|
||||
const { SERVER_PORT, SERVER_BASE_URL } = process.env;
|
||||
const SERVER_BASE_PATH = process.env.SERVER_BASE_PATH || '/api/';
|
||||
const PROXY_TARGET_URL = process.env.PROXY_TARGET_URL || `http://127.0.0.1:${SERVER_PORT}`;
|
||||
const LOCAL_STORAGE_BASE_URL = process.env.LOCAL_STORAGE_BASE_URL || '/uploads';
|
||||
|
||||
function getLocalStorageProxy() {
|
||||
if (LOCAL_STORAGE_BASE_URL.startsWith('http')) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return {
|
||||
[LOCAL_STORAGE_BASE_URL]: {
|
||||
target: PROXY_TARGET_URL,
|
||||
changeOrigin: true,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
define: {
|
||||
'process.env.SERVER_BASE_URL': SERVER_BASE_URL || SERVER_BASE_PATH,
|
||||
},
|
||||
// only proxy when using `umi dev`
|
||||
// if the assets are built, will not proxy
|
||||
proxy: {
|
||||
[SERVER_BASE_PATH]: {
|
||||
target: PROXY_TARGET_URL,
|
||||
changeOrigin: true,
|
||||
pathRewrite: { [`^${SERVER_BASE_PATH}`]: SERVER_BASE_PATH },
|
||||
},
|
||||
// for local storage
|
||||
...getLocalStorageProxy(),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
exports.getUmiConfig = getUmiConfig;
|
Loading…
Reference in New Issue
Block a user