// Local UI fixture only. This entry point is never compiled into the production server. import { createGameServer } from '../src/server/create-server.js'; import { readFile } from 'node:fs/promises'; import { build } from 'esbuild'; const clientDirectory = process.env.UI_PREVIEW_CLIENT ?? 'dist/client'; const app = await createGameServer({ mongoUri: process.env.TEST_MONGODB_URI!, databaseName: 'dragon_ball_test_preview_20261012', clientDirectory, adminUser: 'preview', adminPassword: 'preview-test-only', environment: 'test' }); // Test-only credentials stay on the fixture server; normal production auth is tested separately. const authorization = `Basic ${Buffer.from('preview:preview-test-only').toString('base64')}`; app.get('/__test/peer', async (_request, reply) => { const index = await readFile(clientDirectory + '/index.html', 'utf8'); return reply.type('text/html; charset=utf-8').send(index.replace('
', '')); }); app.get('/__test/peer-monitor.js', async (_request, reply) => reply.type('application/javascript').send(await readFile('tests/peer-browser-monitor.js', 'utf8'))); app.get('/__test/admin', async (_request, reply) => { const response = await app.inject({ url: '/admin/analytics', headers: { authorization } }); const bootstrap = ''; return reply.type('text/html; charset=utf-8').send(response.body.replace('', `${bootstrap}`)); }); app.get('/__test/admin-api/*', async (request, reply) => { const tail = (request.params as { '*': string })['*']; const query = request.url.includes('?') ? request.url.slice(request.url.indexOf('?')) : ''; const response = await app.inject({ url: `/api/admin/analytics/${tail}${query}`, headers: { authorization } }); return reply.code(response.statusCode).type('application/json').send(response.body); }); app.get('/__test/mobile', (request, reply) => { const query = request.query as { width?: string; height?: string }; const width = query.width === '320' ? 320 : 390, height = query.height === '568' ? 568 : 844; return reply.type('text/html; charset=utf-8').send(`