/** * 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= 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.'));