mirror of
https://github.com/nocobase/nocobase.git
synced 2026-12-06 22:23:41 +08:00
* 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>
53 lines
1.8 KiB
TypeScript
53 lines
1.8 KiB
TypeScript
/**
|
|
* This file is part of the NocoBase (R) project.
|
|
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
* Authors: NocoBase Team.
|
|
*
|
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
*/
|
|
|
|
function normalizePublicPath(value: string) {
|
|
let normalized = value || '/';
|
|
if (!normalized.startsWith('/')) {
|
|
normalized = `/${normalized}`;
|
|
}
|
|
if (!normalized.endsWith('/')) {
|
|
normalized = `${normalized}/`;
|
|
}
|
|
return normalized.replace(/\/{2,}/g, '/');
|
|
}
|
|
|
|
function escapeRegExp(value: string) {
|
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
}
|
|
|
|
function createSettingsPathPattern(appPublicPath: string) {
|
|
const publicPath = normalizePublicPath(appPublicPath);
|
|
return new RegExp(`^${escapeRegExp(publicPath)}settings(?:/|$)`);
|
|
}
|
|
|
|
export function isSettingsDevPath(url: string, appPublicPath: string) {
|
|
const [pathname] = String(url || '/').split(/[?#]/, 1);
|
|
return createSettingsPathPattern(appPublicPath).test(pathname);
|
|
}
|
|
|
|
export function rewriteSettingsDevProxyPath(url: string, appPublicPath: string) {
|
|
const publicPath = normalizePublicPath(appPublicPath);
|
|
const settingsRoot = `${publicPath}settings`;
|
|
const settingsRootWithoutTrailingSlash = new RegExp(`^${escapeRegExp(settingsRoot)}(?=[?#]|$)`);
|
|
|
|
return url.replace(settingsRootWithoutTrailingSlash, `${settingsRoot}/`);
|
|
}
|
|
|
|
export function createSettingsDevProxyOptions(appPublicPath: string, settingsPort: number) {
|
|
return {
|
|
context: (pathname: string) => isSettingsDevPath(pathname, appPublicPath),
|
|
target: `http://127.0.0.1:${settingsPort}`,
|
|
changeOrigin: true,
|
|
ws: true,
|
|
xfwd: true,
|
|
pathRewrite: (pathname: string) => rewriteSettingsDevProxyPath(pathname, appPublicPath),
|
|
};
|
|
}
|