Files
Zeke Zhangandchenos f8b6bc07af feat(client-v2): add standalone settings SPA (#10187)
* feat(client-v2): add standalone settings SPA

* style(client-v2): use primary header color

* fix(plugin-ui-layout): hide mobile menu

* style(client-v2): regroup settings action

* fix(client-v2): match settings header color

* fix(client-v2): group portal manager

* fix(client-v2): group topbar managers

* feat(multi-portal): add portal routes

* fix(app): normalize settings dev root

* feat(auth): add settings SPA sign-in

* docs(auth): add settings sign-in plan

* fix(client-v2): align settings embed layout

* fix(client-v2): normalize settings app URLs

* feat(multi-portal): unify client v2 portals

* fix(ci): repair PR validation failures

* fix(client-v2): flatten scoped settings URLs

* fix(client-v2): redirect roots to settings

* fix(cli): initialize AI portal env defaults

* fix(cli): remove portal setup from init

* fix(cli): skip unsupported portal registry sync

* fix(cli): narrow init env config types

* refactor(multi-portal): use fixed portal uids

* fix(cli): skip portal registry sync during install

* fix(plugin-multi-portal): allow reserved slugs

* fix(client-v2): normalize settings app roots

---------

Co-authored-by: chenos <chenlinxh@gmail.com>
2026-07-29 18:35:33 +08:00

146 lines
4.4 KiB
JavaScript

const packageJson = require('./package.json');
const { resolvePublicPath, resolveV2PublicPath } = require('../cli-v1/src/util');
const { getPackagePaths, IndexGenerator, generatePlugins, generateAllPlugins } = require('./common.js');
console.log('VERSION: ', packageJson.version);
function getUmiConfig() {
const {
APP_PORT,
APP_V2_PORT,
APP_SETTINGS_PORT,
API_BASE_URL,
API_CLIENT_STORAGE_TYPE,
API_CLIENT_STORAGE_PREFIX,
APP_PUBLIC_PATH,
} = process.env;
const API_BASE_PATH = process.env.API_BASE_PATH || '/api/';
const normalizedAppPublicPath = resolvePublicPath(APP_PUBLIC_PATH || '/');
const V2_PUBLIC_PATH = resolveV2PublicPath(APP_PUBLIC_PATH || '/');
const PROXY_TARGET_URL = process.env.PROXY_TARGET_URL || `http://127.0.0.1:${APP_PORT}`;
const LOCAL_STORAGE_BASE_URL = 'storage/uploads/';
const STATIC_PATH = 'static/';
function getLocalStorageProxy() {
if (LOCAL_STORAGE_BASE_URL.startsWith('http')) {
return {};
}
return {
[normalizedAppPublicPath + LOCAL_STORAGE_BASE_URL]: {
target: PROXY_TARGET_URL,
changeOrigin: true,
},
[normalizedAppPublicPath + STATIC_PATH]: {
target: PROXY_TARGET_URL,
changeOrigin: true,
},
};
}
function getClientV2Proxy() {
if (!APP_V2_PORT) {
return {};
}
return {
[V2_PUBLIC_PATH]: {
target: `http://127.0.0.1:${APP_V2_PORT}`,
changeOrigin: true,
ws: true,
pathRewrite: { [`^${V2_PUBLIC_PATH}`]: V2_PUBLIC_PATH },
onProxyReq: (proxyReq, req, res) => {
if (req?.ip) {
proxyReq.setHeader('X-Forwarded-For', req.ip);
}
},
},
};
}
function getSettingsProxy() {
if (!APP_SETTINGS_PORT) {
return {};
}
const settingsTarget = `http://127.0.0.1:${APP_SETTINGS_PORT}`;
const settingsPath = `${normalizedAppPublicPath}settings`;
const createProxyOptions = () => ({
target: settingsTarget,
changeOrigin: true,
ws: true,
onProxyReq: (proxyReq, req) => {
if (req?.ip) {
proxyReq.setHeader('X-Forwarded-For', req.ip);
}
},
});
return {
[`${settingsPath}{,/**}`]: createProxyOptions(),
};
}
return {
alias: getPackagePaths().reduce((memo, item) => {
memo[item[0]] = item[1];
return memo;
}, {}),
define: {
'process.env.APP_PUBLIC_PATH': process.env.APP_PUBLIC_PATH,
'process.env.WS_PATH': process.env.WS_PATH,
'process.env.API_BASE_URL': API_BASE_URL || API_BASE_PATH,
'process.env.API_CLIENT_STORAGE_PREFIX': API_CLIENT_STORAGE_PREFIX,
'process.env.API_CLIENT_STORAGE_TYPE': API_CLIENT_STORAGE_TYPE,
'process.env.API_CLIENT_SHARE_TOKEN': process.env.API_CLIENT_SHARE_TOKEN || 'false',
'process.env.APP_ENV': process.env.APP_ENV,
'process.env.VERSION': packageJson.version,
'process.env.WEBSOCKET_URL': process.env.WEBSOCKET_URL,
'process.env.__E2E__': process.env.__E2E__,
},
// only proxy when using `umi dev`
// if the assets are built, will not proxy
proxy: {
[API_BASE_PATH]: {
target: PROXY_TARGET_URL,
changeOrigin: true,
pathRewrite: { [`^${API_BASE_PATH}`]: API_BASE_PATH },
onProxyRes(proxyRes, req, res) {
if (req.headers.accept === 'text/event-stream') {
res.writeHead(res.statusCode, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-transform',
Connection: 'keep-alive',
});
}
},
onProxyReq: (proxyReq, req, res) => {
if (req?.ip) {
proxyReq.setHeader('X-Forwarded-For', req.ip);
}
},
},
// for local storage
...getLocalStorageProxy(),
// v2 shell dev server proxy
...getClientV2Proxy(),
// standalone Settings dev server proxy
...getSettingsProxy(),
},
};
}
function resolveNocobasePackagesAlias(config) {
const pkgs = getPackagePaths();
for (const [pkg, dir] of pkgs) {
config.module.rules.get('ts-in-node_modules').include.add(dir);
config.resolve.alias.set(pkg, dir);
}
}
exports.getUmiConfig = getUmiConfig;
exports.resolveNocobasePackagesAlias = resolveNocobasePackagesAlias;
exports.IndexGenerator = IndexGenerator;
exports.generatePlugins = generatePlugins;
exports.generateAllPlugins = generateAllPlugins;