Files
crosscode-platform/apps/accounts/backend/src/index.ts
T
joshuaandClaude Opus 5.5 069b66fd30 Accounts 1.0.0 backend: OIDC provider, sign-in steps, account and admin API
oidc-provider 9.13.3 with PKCE, ES256, crosscode.identity/1 claims and
back-channel logout; clients are the linked products (Connect). Sign-in
steps (password, sign-up, email check, 2FA and its setup, privacy notice,
news question, password reset) survive to the product. Account page and
admin API, church profile, export and deletion fan-out, Hub v2 client,
jobs. End-to-end tests with a test product on openid-client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 13:33:49 +02:00

44 lines
1.5 KiB
TypeScript

/**
* Starts Accounts: database, OIDC provider, HTTP server, jobs, and (on a Hub install) registering
* with the Hub from HUB_LICENCE_KEY.
*/
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 } from './hub/client.js';
import { startJobs } from './jobs.js';
import { loadConfig } from './lib/config.js';
import { createProvider } from './oidc/provider.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 provider = await createProvider(ctx);
const app = createApp(ctx, provider);
const server = app.listen(config.port, () => console.log(`[accounts] Listening on ${config.port} (${config.publicUrl}).`));
const stopJobs = await startJobs(ctx, url);
connectFromEnv(ctx).then((r) => {
if (r.connected) heartbeat(ctx).catch(() => {});
}).catch(() => {});
const stop = async () => {
server.close();
await stopJobs();
await db.$disconnect();
process.exit(0);
};
process.on('SIGTERM', stop);
process.on('SIGINT', stop);
}
main().catch((e) => {
console.error('[accounts] Failed to start:', e);
process.exit(1);
});