feat: production routing support for subdomain and custom domain modes
Some checks failed
CI / ruff (push) Successful in 10s
CI / pytest (push) Failing after 45m18s
CI / validate (push) Successful in 24s
CI / dependency-scanning (push) Successful in 30s
CI / docs (push) Has been skipped
CI / deploy (push) Has been skipped

Double-mount store routes at /store/* and /store/{store_code}/* so the
same handlers work in dev path-based, prod path-based, prod subdomain,
and prod custom-domain modes.  Wire StorePlatform.custom_subdomain into
StoreContextMiddleware for per-platform subdomain overrides.  Add admin
custom-domain management UI, fix stale /shop/ reset link, add
/merchants/ to reserved paths, and server-render window.STORE_CODE for
JS that previously parsed the URL.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-26 00:15:06 +01:00
parent 6a82d7c12d
commit ce5b54f27b
36 changed files with 822 additions and 151 deletions

View File

@@ -20,6 +20,13 @@ function adminStoreDetail() {
showDeleteStoreModal: false,
showDeleteStoreFinalModal: false,
// Domain management state
domains: [],
domainsLoading: false,
showAddDomainForm: false,
domainSaving: false,
newDomain: { domain: '', platform_id: '' },
// Initialize
async init() {
// Load i18n translations
@@ -42,9 +49,12 @@ function adminStoreDetail() {
this.storeCode = match[1];
detailLog.info('Viewing store:', this.storeCode);
await this.loadStore();
// Load subscription after store is loaded
// Load subscription and domains after store is loaded
if (this.store?.id) {
await this.loadSubscriptions();
await Promise.all([
this.loadSubscriptions(),
this.loadDomains(),
]);
}
} else {
detailLog.error('No store code in URL');
@@ -180,6 +190,90 @@ function adminStoreDetail() {
}
},
// ====================================================================
// DOMAIN MANAGEMENT
// ====================================================================
async loadDomains() {
if (!this.store?.id) return;
this.domainsLoading = true;
try {
const url = `/admin/stores/${this.store.id}/domains`;
const response = await apiClient.get(url);
this.domains = response.domains || [];
detailLog.info('Domains loaded:', this.domains.length);
} catch (error) {
if (error.status === 404) {
this.domains = [];
} else {
detailLog.warn('Failed to load domains:', error.message);
}
} finally {
this.domainsLoading = false;
}
},
async addDomain() {
if (!this.newDomain.domain || this.domainSaving) return;
this.domainSaving = true;
try {
const payload = { domain: this.newDomain.domain };
if (this.newDomain.platform_id) {
payload.platform_id = parseInt(this.newDomain.platform_id);
}
await apiClient.post(`/admin/stores/${this.store.id}/domains`, payload);
Utils.showToast('Domain added successfully', 'success');
this.showAddDomainForm = false;
this.newDomain = { domain: '', platform_id: '' };
await this.loadDomains();
} catch (error) {
Utils.showToast(error.message || 'Failed to add domain', 'error');
} finally {
this.domainSaving = false;
}
},
async verifyDomain(domainId) {
try {
const response = await apiClient.post(`/admin/stores/domains/${domainId}/verify`);
Utils.showToast(response.message || 'Domain verified!', 'success');
await this.loadDomains();
} catch (error) {
Utils.showToast(error.message || 'Verification failed — check DNS records', 'error');
}
},
async toggleDomainActive(domainId, activate) {
try {
await apiClient.put(`/admin/stores/domains/${domainId}`, { is_active: activate });
Utils.showToast(activate ? 'Domain activated' : 'Domain deactivated', 'success');
await this.loadDomains();
} catch (error) {
Utils.showToast(error.message || 'Failed to update domain', 'error');
}
},
async setDomainPrimary(domainId) {
try {
await apiClient.put(`/admin/stores/domains/${domainId}`, { is_primary: true });
Utils.showToast('Domain set as primary', 'success');
await this.loadDomains();
} catch (error) {
Utils.showToast(error.message || 'Failed to set primary domain', 'error');
}
},
async deleteDomain(domainId, domainName) {
if (!confirm(`Delete domain "${domainName}"? This cannot be undone.`)) return;
try {
await apiClient.delete(`/admin/stores/domains/${domainId}`);
Utils.showToast('Domain deleted', 'success');
await this.loadDomains();
} catch (error) {
Utils.showToast(error.message || 'Failed to delete domain', 'error');
}
},
// Refresh store data
async refresh() {
detailLog.info('=== STORE REFRESH TRIGGERED ===');