Merge branch 'fix/proxy-check-reason'

This commit is contained in:
2026-12-03 10:54:04 +02:00
7 changed files with 97 additions and 9 deletions
+18
View File
@@ -5,6 +5,24 @@ versions follow [Semantic Versioning](https://semver.org/).
## [Unreleased] ## [Unreleased]
## [2.26.2] - 2026-12-03
No migration; no API is removed.
### Fixed
- **Proxy done said only "fetch failed".** It now says why the Hub's server couldn't reach the
site (the error's code and message: DNS, the certificate, the connection, or no answer within 15
seconds) with what to check. A browser can open a site the Hub can't: a certificate without its
intermediate (browsers fill it in, Node doesn't), a DNS record not yet seen from the Hub's server,
a firewall in between.
- **A Website or App added to a church had no site admin** when the New install form's "Site admin
email" was left blank, so it got no `HUB_ADMIN_EMAIL` and nobody became its first Owner. A blank
site admin is now the church's own from its other installs (Accounts' first).
- **The "site is ready" email sent the Website's and App's admin to /setup**, which they don't have.
It now opens their admin and says to sign in with the site admin's address to become the Owner.
Events and Accounts keep their setup link.
## [2.26.1] - 2026-11-30 ## [2.26.1] - 2026-11-30
No migration; no API is removed. Contracts 1.24.0 (vendored). No migration; no API is removed. Contracts 1.24.0 (vendored).
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "events-hub-backend", "name": "events-hub-backend",
"version": "2.26.1", "version": "2.26.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "events-hub-backend", "name": "events-hub-backend",
"version": "2.26.1", "version": "2.26.2",
"hasInstallScript": true, "hasInstallScript": true,
"dependencies": { "dependencies": {
"@anthropic-ai/sdk": "^1.3.0", "@anthropic-ai/sdk": "^1.3.0",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "events-hub-backend", "name": "events-hub-backend",
"version": "2.26.1", "version": "2.26.2",
"private": true, "private": true,
"description": "Cross Events Hub — API for managing Cross Events installs, licences and heartbeats", "description": "Cross Events Hub — API for managing Cross Events installs, licences and heartbeats",
"main": "src/index.js", "main": "src/index.js",
+34 -3
View File
@@ -689,6 +689,11 @@ async function newInstall(input, admin, now = new Date()) {
// it. A church without Accounts has it installed first, in the same batch; one with an older // it. A church without Accounts has it installed first, in the same batch; one with an older
// Accounts is refused until it's updated. // Accounts is refused until it's updated.
const first = await requiredFirst({ release, product, siblings, input, domain, server, now }); const first = await requiredFirst({ release, product, siblings, input, domain, server, now });
// 2.26.2: left blank, the site admin is the church's own from its other installs (Accounts' first),
// so a Website or App added later still has the address its first Owner signs in with
// (HUB_ADMIN_EMAIL); before, it had none and nobody could open the admin.
const known = siblings.find(s => s.product === 'accounts' && s.adminEmail) || siblings.find(s => s.adminEmail) || null;
const siteAdmin = adminEmail ? { name: input.adminName || null, email: adminEmail } : { name: input.adminName || known?.adminName || null, email: known?.adminEmail || null };
const add = siblings.length > 0 || !!first; const add = siblings.length > 0 || !!first;
// The name is free again after a failed install (its ports were already freed) or an uninstall. // The name is free again after a failed install (its ports were already freed) or an uninstall.
// A failed install's record goes; a removed one keeps its history under another name (the // A failed install's record goes; a removed one keeps its history under another name (the
@@ -727,7 +732,7 @@ async function newInstall(input, admin, now = new Date()) {
if (!licence) licence = (await generateLicence(tx, { customerId: customer.id, product: p, now })).licence; if (!licence) licence = (await generateLicence(tx, { customerId: customer.id, product: p, now })).licence;
const ports = await portsFor(); const ports = await portsFor();
const d = await tx.deployment.create({ const d = await tx.deployment.create({
data: { serverId: server.id, customerId: customer.id, licenceId: licence.id, product: p, shortName, domain: dom, webPort: ports.web, apiPort: ports.api, timezone: input.timezone || null, adminName: input.adminName || null, adminEmail: adminEmail || null, isDemo: !!customer.isDemo, status: 'installing' }, data: { serverId: server.id, customerId: customer.id, licenceId: licence.id, product: p, shortName, domain: dom, webPort: ports.web, apiPort: ports.api, timezone: input.timezone || null, adminName: siteAdmin.name, adminEmail: siteAdmin.email, isDemo: !!customer.isDemo, status: 'installing' },
}); });
await tx.port.updateMany({ where: { port: { in: [ports.web, ports.api] } }, data: { deploymentId: d.id } }); await tx.port.updateMany({ where: { port: { in: [ports.web, ports.api] } }, data: { deploymentId: d.id } });
return { d, ports }; return { d, ports };
@@ -1090,13 +1095,31 @@ async function listWhere(q = {}) {
return and.length ? { AND: and } : {}; return and.length ? { AND: and } : {};
} }
/**
* 2.26.2: why a fetch from the Hub failed. Node's fetch only says "fetch failed"; the reason (DNS,
* the certificate, the connection) is in `cause`. A browser can still open the site when the
* Hub's server can't: a certificate without its intermediate (browsers fetch it, Node doesn't), an
* address only an IPv6 or a local resolver knows, a firewall in between.
*/
function fetchFailure(e) {
if (e?.name === 'TimeoutError' || e?.name === 'AbortError') return 'no answer within 15 seconds from the Hub\'s server.';
const c = e?.cause;
const code = String(c?.code || '');
const detail = [code, c?.message && c.message !== code ? c.message : ''].filter(Boolean).join(': ');
let hint = '';
if (code === 'ENOTFOUND' || code === 'EAI_AGAIN') hint = 'The Hub\'s server can\'t find this address in DNS yet: check the record, and that it has spread.';
else if (/CERT|SELF_SIGNED|UNABLE_TO_(VERIFY|GET)|ERR_TLS|SSL/i.test(code + ' ' + (c?.message || ''))) hint = 'The Hub doesn\'t trust the site\'s certificate: in FastPanel, check the site has its Let\'s Encrypt certificate with the full chain (a browser fills in a missing intermediate, the Hub doesn\'t).';
else if (/ECONNREFUSED|ECONNRESET|ETIMEDOUT|EHOSTUNREACH|ENETUNREACH|UND_ERR_CONNECT_TIMEOUT|UND_ERR_SOCKET/.test(code)) hint = 'Nothing answered on port 443 from the Hub\'s server: check the central server\'s firewall and that FastPanel has the site.';
return `${e?.message || 'no answer'}${detail ? ` (${detail})` : ''}.${hint ? ` ${hint}` : ''}`;
}
/** Proxy done (§7.8): check the public addresses, then Live and the welcome email. */ /** Proxy done (§7.8): check the public addresses, then Live and the welcome email. */
async function proxyDone(deploymentId, now = new Date(), fetcher = fetch) { async function proxyDone(deploymentId, now = new Date(), fetcher = fetch) {
const d = await prisma.deployment.findUnique({ where: { id: deploymentId }, include: { install: true, customer: true } }); const d = await prisma.deployment.findUnique({ where: { id: deploymentId }, include: { install: true, customer: true } });
if (!d) throw fail(404, 'NOT_FOUND', 'Not found.'); if (!d) throw fail(404, 'NOT_FOUND', 'Not found.');
const problems = []; const problems = [];
const get = async url => { const get = async url => {
try { return await fetcher(url, { redirect: 'manual', signal: AbortSignal.timeout(15000) }); } catch (e) { problems.push(`${url}: ${e?.message || 'no answer'}`); return null; } try { return await fetcher(url, { redirect: 'manual', signal: AbortSignal.timeout(15000) }); } catch (e) { problems.push(`${url}: ${fetchFailure(e)}`); return null; }
}; };
const site = await get(`https://${d.domain}/`); const site = await get(`https://${d.domain}/`);
if (site && !(site.status >= 200 && site.status < 400)) problems.push(`https://${d.domain}/ answered ${site.status}.`); if (site && !(site.status >= 200 && site.status < 400)) problems.push(`https://${d.domain}/ answered ${site.status}.`);
@@ -1115,13 +1138,21 @@ async function proxyDone(deploymentId, now = new Date(), fetcher = fetch) {
if (problems.length) return { live: false, problems }; if (problems.length) return { live: false, problems };
await prisma.deployment.update({ where: { id: d.id }, data: { status: 'live', liveAt: now } }); await prisma.deployment.update({ where: { id: d.id }, data: { status: 'live', liveAt: now } });
const name = PRODUCT_NAMES[d.product]; const name = PRODUCT_NAMES[d.product];
// 2.26.2: only Events and Accounts have a setup; the Website and the App make the first Owner of
// whoever signs in with this (the site admin's) address, from their /admin.
const hasSetup = d.product === 'events' || d.product === 'accounts';
const admin = siteAdminEmail(d);
await emailSiteAdmin(d, `Your ${name} site is ready`, { await emailSiteAdmin(d, `Your ${name} site is ready`, {
heading: `Your ${name} site is ready`, heading: `Your ${name} site is ready`,
sub: `https://${d.domain}`, sub: `https://${d.domain}`,
blocks: [ blocks: hasSetup ? [
{ p: `${d.customer?.name || 'Your church'}'s ${name} site is ready.` }, { p: `${d.customer?.name || 'Your church'}'s ${name} site is ready.` },
{ p: 'To start, open the setup: it creates your admin account and walks you through the settings.' }, { p: 'To start, open the setup: it creates your admin account and walks you through the settings.' },
{ button: { label: 'Start the setup', url: `https://${d.domain}/setup` } }, { button: { label: 'Start the setup', url: `https://${d.domain}/setup` } },
] : [
{ p: `${d.customer?.name || 'Your church'}'s ${name} site is ready.` },
{ p: `To start, open its admin and sign in with your church account${admin ? ` (${admin})` : ''}: the first time you do, you become its Owner.` },
{ button: { label: `Open the ${name} admin`, url: `https://${d.domain}/admin` } },
], ],
}); });
return { live: true, problems: [] }; return { live: true, problems: [] };
+39
View File
@@ -174,6 +174,45 @@ describe('jobs', () => {
expect(ready.text).toContain('Start the setup: https://events.hope.co.za/setup'); expect(ready.text).toContain('Start the setup: https://events.hope.co.za/setup');
}); });
test('2.26.2: Proxy done says why a fetch failed, not just "fetch failed"', async () => {
const { server } = await joinServer();
await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' });
const { deployment } = await jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'events.hope.co.za' }, admin, NOW);
const failing = cause => async () => { throw new TypeError('fetch failed', { cause }); };
const dns = await jobs.proxyDone(deployment.id, NOW, failing(Object.assign(new Error('getaddrinfo ENOTFOUND events.hope.co.za'), { code: 'ENOTFOUND' })));
expect(dns.live).toBe(false);
expect(dns.problems[0]).toContain('fetch failed (ENOTFOUND: getaddrinfo ENOTFOUND events.hope.co.za)');
expect(dns.problems[0]).toContain('in DNS');
const cert = await jobs.proxyDone(deployment.id, NOW, failing(Object.assign(new Error('unable to verify the first certificate'), { code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' })));
expect(cert.problems[0]).toContain('UNABLE_TO_VERIFY_LEAF_SIGNATURE');
expect(cert.problems[0]).toContain('full chain');
const slow = await jobs.proxyDone(deployment.id, NOW, async () => { throw new DOMException('The operation was aborted due to timeout', 'TimeoutError'); });
expect(slow.problems[0]).toContain('no answer within 15 seconds');
});
test('2.26.2: the Website\'s and App\'s ready email opens the admin (they have no setup)', async () => {
const { server } = await joinServer();
const d = await db.deployment.create({ data: { id: 'app-hope', serverId: server.id, customerId: 'cust-1', product: 'app', shortName: 'hope', domain: 'app.hope.co.za', webPort: 20100, apiPort: 20101, status: 'waiting_for_proxy', adminName: 'Jane', adminEmail: 'jane@hope.test' } });
const ok = async url => ({ status: url.endsWith('/') ? 200 : 404, headers: new Headers({ 'x-powered-by': 'Express' }), json: async () => ({ version: null }) });
expect(await jobs.proxyDone(d.id, NOW, ok)).toEqual({ live: true, problems: [] });
const ready = mockMails.find(m => m.subject.includes('site is ready'));
expect(ready.html).toContain('href="https://app.hope.co.za/admin"');
expect(ready.text).toContain('jane@hope.test');
expect(ready.text).not.toContain('/setup');
});
test('2.26.2: a new install without a site admin takes the church\'s from its other installs', async () => {
const { server } = await joinServer();
await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' });
const { deployment: ev } = await jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'events.hope.co.za', adminName: 'Jane', adminEmail: 'jane@hope.test' }, admin, NOW);
await db.deployment.update({ where: { id: ev.id }, data: { status: 'live' } });
await db.release.create({ data: { id: 'ra10', product: 'accounts', version: '1.0.0', releasedAt: NOW } });
const { deployment: acc } = await jobs.newInstall({ customerId: 'cust-1', serverId: server.id, shortName: 'hope', domain: 'accounts.hope.co.za', product: 'accounts' }, admin, NOW);
expect(acc).toMatchObject({ adminName: 'Jane', adminEmail: 'jane@hope.test' });
const job = await db.job.findFirst({ where: { deploymentId: acc.id, type: 'install' } });
if (job) expect(JSON.stringify(job.args)).toContain('jane@hope.test');
});
test('a failed install frees its ports again', async () => { test('a failed install frees its ports again', async () => {
const { server } = await joinServer(); const { server } = await joinServer();
await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' }); await servers.setServerConfig(server.id, { TRUST_PROXY: 'loopback' });
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "events-hub-frontend", "name": "events-hub-frontend",
"version": "2.26.1", "version": "2.26.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "events-hub-frontend", "name": "events-hub-frontend",
"version": "2.26.1", "version": "2.26.2",
"dependencies": { "dependencies": {
"lucide-react": "^0.536.0", "lucide-react": "^0.536.0",
"next": "^15.5.24", "next": "^15.5.24",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "events-hub-frontend", "name": "events-hub-frontend",
"version": "2.26.1", "version": "2.26.2",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev -p 3200", "dev": "next dev -p 3200",