feat(website): crosscode website.sh and signing in through Accounts

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>
This commit is contained in:
2026-11-25 09:27:07 +02:00
co-authored by Claude Opus 5.5
parent 79121bc447
commit 58960b5e93
43 changed files with 2361 additions and 77 deletions
+23 -14
View File
@@ -2,27 +2,25 @@
* The Express app (docs/WEBSITE-1.0-PLAN.md §1). Everything is under /api, so the site and its API
* share one address (as Events and Accounts): nginx sends /api to this backend and the rest to Next.js.
*
* /api/health version and database, for monitoring, `crosscode deploy` and the Hub
* /api/v1/site/… the public site (what visitors see: the latest published version)
* /api/health version and database, for monitoring, `crosscode deploy` and the Hub
* /api/v1/site/… the public site (what visitors see: the latest published version)
* /api/auth/… signing in to the admin through the church's Accounts
* /api/accounts/v1/events Accounts' signed calls (user.updated / export / deleted)
* /api/links/v1/… Connect and Disconnect with the church's other products
* /api/v1/admin/… the admin (signed in, by role)
*
* To come (§1): /api/v1/admin/… (content, publish, preview links), /api/uploads/…, the event feed
* (/api/links/v1/*, as Events 2.4) and the Hub client.
* To come (§1): the admin's content, publish and preview links, /api/uploads/…, the event feed.
*/
import express from 'express';
import type { Ctx } from './context.js';
import { handle, sendError } from './http.js';
import { authRouter } from './auth/routes.js';
import { requireRole } from './auth/sessions.js';
import { dbUp } from './hub/client.js';
import { ApiError, handle, sendError } from './http.js';
import { appVersion } from './lib/version.js';
import { linksRouter } from './links/routes.js';
import { siteStatus } from './site/status.js';
async function dbUp(ctx: Ctx): Promise<boolean> {
try {
await ctx.db.$queryRaw`SELECT 1`;
return true;
} catch {
return false;
}
}
export function createApp(ctx: Ctx) {
const app = express();
app.disable('x-powered-by');
@@ -45,12 +43,23 @@ export function createApp(ctx: Ctx) {
site.get('/status', handle(() => siteStatus(ctx)));
app.use('/api/v1/site', site);
app.use('/api', authRouter(ctx));
app.use('/api', linksRouter(ctx));
const admin = express.Router();
admin.use(express.json({ limit: '256kb' }));
admin.use(requireRole(ctx, 'viewer'));
admin.get('/me', handle(async (req) => ({ user: req.signed!.user, mfa: req.signed!.mfa })));
app.use('/api/v1/admin', admin);
app.use('/api', (_req, res) => {
res.status(404).json({ error: { code: 'NOT_FOUND', message: 'There is no such API endpoint.' } });
});
app.use((err: unknown, _req: express.Request, res: express.Response, next: express.NextFunction) => {
if (res.headersSent) return next(err);
const e = err as { type?: string };
if (e?.type === 'entity.parse.failed') return sendError(res, new ApiError(400, 'VALIDATION', 'The body must be JSON.'));
return sendError(res, err);
});
return app;