crosscode: scripts/products/website.sh (ports 5300/3300, uploads in the export), crosscode add <church> website (needs Accounts; www.<address> or the Cross Code address), one install_app for Accounts and the Website, env template copy, bats tests. Backend: Hub client (protocol v2, product website), crosscode.link/1 with automatic connect to the church's Accounts, sign-in through @crosscode/auth-client with the Website's own session and roles, the first Owner from HUB_ADMIN_EMAIL (verified), 2FA for Owners and Admins, back-channel logout, Accounts' user.* calls, and the church export. Frontend: admin sign-in/out and the sign-in problem page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.6 KiB
TypeScript
43 lines
1.6 KiB
TypeScript
/**
|
|
* Starts the Church Website's backend: database, HTTP server, and (on a Hub install) registering
|
|
* with the Hub from HUB_LICENCE_KEY, then heartbeats, which also link the site to the church's
|
|
* Accounts once the Hub lists it. The other jobs (YouTube feed, storage count, sitemap, feed sync)
|
|
* come with their features (docs/WEBSITE-1.0-PLAN.md §1).
|
|
*/
|
|
import 'dotenv/config';
|
|
import { PrismaPg } from '@prisma/adapter-pg';
|
|
import { PrismaClient } from './generated/prisma/client.js';
|
|
import { createApp } from './app.js';
|
|
import { createCtx } from './context.js';
|
|
import { connectFromEnv, heartbeat, startHeartbeats } from './hub/client.js';
|
|
import { loadConfig } from './lib/config.js';
|
|
|
|
async function main() {
|
|
const config = loadConfig();
|
|
const url = process.env.DATABASE_URL;
|
|
if (!url) throw new Error('DATABASE_URL isn\'t set.');
|
|
const db = new PrismaClient({ adapter: new PrismaPg({ connectionString: url, connectionTimeoutMillis: 5000 }) });
|
|
const ctx = createCtx(config, db);
|
|
const app = createApp(ctx);
|
|
const server = app.listen(config.port, () => console.log(`[website] Listening on ${config.port} (${config.publicUrl}).`));
|
|
const stopHeartbeats = startHeartbeats(ctx);
|
|
|
|
connectFromEnv(ctx).then((r) => {
|
|
if (r.connected || r.reason === 'already') heartbeat(ctx).catch(() => {});
|
|
}).catch(() => {});
|
|
|
|
const stop = async () => {
|
|
stopHeartbeats();
|
|
server.close();
|
|
await db.$disconnect();
|
|
process.exit(0);
|
|
};
|
|
process.on('SIGTERM', stop);
|
|
process.on('SIGINT', stop);
|
|
}
|
|
|
|
main().catch((e) => {
|
|
console.error('[website] Failed to start:', e);
|
|
process.exit(1);
|
|
});
|