Use per-deploy preview hosts under the site root domain.
Build hosts as <userPrefix>-<deploymentNumber>-preview.<rootDomain> from FRONTEND_URL, wire them through ingress/TLS, and open them from the preview API. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,3 +1,49 @@
|
||||
function resolvePlatformDomainFromEnv(): string {
|
||||
const frontendUrl = process.env.FRONTEND_URL;
|
||||
if (frontendUrl) {
|
||||
try {
|
||||
const url = new URL(frontendUrl);
|
||||
if (url.hostname && !/^\d+\.\d+\.\d+\.\d+$/.test(url.hostname)) {
|
||||
return url.hostname;
|
||||
}
|
||||
} catch {
|
||||
// ignore parse errors and fall back to PLATFORM_DOMAIN
|
||||
}
|
||||
}
|
||||
return process.env.PLATFORM_DOMAIN || 'apps.cloudhost.local';
|
||||
}
|
||||
|
||||
function stripLeadingSubdomain(hostname: string): string {
|
||||
const h = (hostname || '').toLowerCase();
|
||||
if (!h) return h;
|
||||
// If it looks like an IP (IPv4 or IPv6), don't try to strip labels.
|
||||
if (h.includes(':') || /^\d+\.\d+\.\d+\.\d+$/.test(h)) {
|
||||
return h;
|
||||
}
|
||||
const parts = h.split('.').filter(Boolean);
|
||||
if (parts.length >= 3) {
|
||||
return parts.slice(1).join('.');
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
function resolvePreviewRootDomainFromEnv(): string {
|
||||
const frontendUrl = process.env.FRONTEND_URL;
|
||||
if (frontendUrl) {
|
||||
try {
|
||||
const url = new URL(frontendUrl);
|
||||
if (url.hostname) {
|
||||
return stripLeadingSubdomain(url.hostname);
|
||||
}
|
||||
} catch {
|
||||
// ignore and fall back
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: strip from PLATFORM_DOMAIN if it's already a subdomain host.
|
||||
return stripLeadingSubdomain(process.env.PLATFORM_DOMAIN || 'apps.cloudhost.local');
|
||||
}
|
||||
|
||||
export default () => ({
|
||||
nodeEnv: process.env.NODE_ENV || 'development',
|
||||
port: parseInt(process.env.PORT || '4000', 10),
|
||||
@@ -60,7 +106,8 @@ export default () => ({
|
||||
},
|
||||
|
||||
platform: {
|
||||
domain: process.env.PLATFORM_DOMAIN || 'apps.cloudhost.local',
|
||||
domain: resolvePlatformDomainFromEnv(),
|
||||
previewRootDomain: resolvePreviewRootDomainFromEnv(),
|
||||
uploadDir: process.env.UPLOAD_DIR || './uploads',
|
||||
/** StorageClass for new PVCs; must support allowVolumeExpansion for disk resize */
|
||||
storageClass: process.env.PLATFORM_STORAGE_CLASS || 'cloudhost-expandable',
|
||||
|
||||
Reference in New Issue
Block a user