Files
crosscode-platform/apps/website/e2e/server.ts
T
joshuaandClaude Opus 5.5 5ed7201efa feat(website): the four templates and the public site
Heritage, Bold, Community and Clean drawing all 26 section variants
with their headers, homepage order and style settings; colours made
safe (WCAG AA) by the backend; fonts and corners from the shared brand
style. Publishing into numbered versions, the content API with live
messages and events and the church profile from Accounts, uploads,
every page kind, simple event pages, Coming soon, 404, sitemap, SEO
basics and the church's JSON-LD. The demo church (npm run demo) and
Playwright e2e: every template's pages pass axe and the SEO checks.
website.sh builds packages/seo. Decision 17 (first Owner) recorded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 10:59:03 +02:00

48 lines
2.4 KiB
TypeScript

/**
* The e2e backend (playwright.config.ts): the Website's backend on port 5310 with the in-memory
* database from the backend tests (no Postgres needed) and the demo church published. The pages
* run with `next dev` on 3310 and send /api here.
*
* Test helpers: POST /test/demo?template=<id> loads the demo church on that template;
* POST /test/design { variants?, style?, home? } changes the design and publishes again.
*/
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import express from 'express';
import { websiteTemplateSchema } from '@crosscode/contracts';
import { createApp } from '../backend/src/app.js';
import { createCtx } from '../backend/src/context.js';
import { loadDemo } from '../backend/src/demo/demoChurch.js';
import { loadConfig } from '../backend/src/lib/config.js';
import { publish } from '../backend/src/site/snapshot.js';
import { memoryDb } from '../backend/tests/support/memoryDb.js';
const here = path.dirname(fileURLToPath(import.meta.url));
const uploads = path.join(here, '.uploads');
fs.mkdirSync(uploads, { recursive: true });
const db = memoryDb();
const ctx = createCtx(loadConfig({ WEBSITE_URL: 'http://localhost:3310', NODE_ENV: 'test', JOBS_ENABLED: 'false', HUB_URL: 'http://127.0.0.1:1', UPLOAD_DIR: uploads, TRUST_PROXY: 'true' }), db as never);
await loadDemo(ctx, websiteTemplateSchema.parse(process.env.DEMO_TEMPLATE ?? 'heritage'), { uploadDir: uploads });
const app = express();
app.post('/test/demo', async (req, res) => {
const t = websiteTemplateSchema.safeParse(req.query.template);
if (!t.success) return res.status(400).json({ error: 'template' });
await loadDemo(ctx, t.data, { uploadDir: uploads });
return res.json({ ok: true, template: t.data });
});
app.post('/test/design', express.json(), async (req, res) => {
const d = (await db.siteDesign.findUnique({ where: { id: 1 } })) as { variants: object; style: object; home: unknown };
await db.siteDesign.update({ where: { id: 1 }, data: {
variants: { ...d.variants, ...(req.body.variants ?? {}) },
style: { ...d.style, ...(req.body.style ?? {}) },
home: req.body.home ?? d.home,
} });
const v = await publish(ctx, { id: 'e2e', role: 'system' });
res.json({ ok: true, version: v.number });
});
app.use(createApp(ctx));
app.listen(5310, '127.0.0.1', () => console.log('[e2e] Website backend on 5310 with the demo church.'));