fix(page-data): harden structural delivery and Portal base URL
Reject /api/page-data/ legacy passthrough, verify live API before send, and resolve delivery links to Portal (8081) instead of Vite (5173). Add local repair/verify scripts for daily-register Page Data flow. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -50,6 +50,28 @@ export function resolvePublicBaseUrl(env = process.env) {
|
||||
return (env.H5_PUBLIC_BASE_URL ?? 'https://m.tkmind.cn').replace(/\/$/, '');
|
||||
}
|
||||
|
||||
const LOCAL_VITE_PUBLIC_BASE_PATTERN = /^https?:\/\/(?:127\.0\.0\.1|localhost):5173$/i;
|
||||
|
||||
/** Agent 交付的 MindSpace 公开页 + Page Data API 应走 Portal,本地开发时勿用 Vite 5173。 */
|
||||
export function resolvePageDataDeliveryBaseUrl(env = process.env) {
|
||||
const explicit = String(
|
||||
env.MEMIND_PAGE_DATA_DELIVERY_BASE_URL ?? env.H5_PORTAL_BASE_URL ?? '',
|
||||
)
|
||||
.trim()
|
||||
.replace(/\/$/, '');
|
||||
if (explicit) return explicit;
|
||||
|
||||
const publicBase = String(env.H5_PUBLIC_BASE_URL ?? '').trim().replace(/\/$/, '');
|
||||
const portalPort = Number(env.H5_PORT ?? 8081);
|
||||
const portalBase = `http://127.0.0.1:${portalPort}`;
|
||||
|
||||
if (publicBase && LOCAL_VITE_PUBLIC_BASE_PATTERN.test(publicBase)) {
|
||||
return portalBase;
|
||||
}
|
||||
if (publicBase) return publicBase;
|
||||
return portalBase;
|
||||
}
|
||||
|
||||
export const PUBLISH_KEY_UUID =
|
||||
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user