// Local UI fixture only. No real login, database, credentials or write API. import { createServer } from 'node:http'; const user = { id: 1, username: 'widget-review', full_name: 'Проверка виджета', role: 'admin' }; const server = createServer((req, res) => { res.setHeader('Access-Control-Allow-Origin', 'http://127.0.0.1:3001'); res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS'); res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-API-Key, X-City-Id'); res.setHeader('Content-Type', 'application/json'); if (req.method === 'OPTIONS') { res.writeHead(204); res.end(); return; } const path = new URL(req.url, 'http://localhost').pathname; if (req.method === 'POST' && path === '/api/v1/auth/login') { res.end(JSON.stringify({ user, accessToken: 'local-widget-fixture-only', refreshToken: 'local-widget-fixture-refresh' })); return; } if (req.method !== 'GET') { res.writeHead(405); res.end('{}'); return; } const data = path === '/api/v1/auth/me' ? user : path === '/api/v1/cities' ? [{ id: 1, name: 'Тестовый город', slug: 'widget-fixture', is_active: true }] : path.endsWith('/sync/status') ? { status: 'ready', database: { schedules_count: 0 } } : []; res.end(JSON.stringify(data)); }); server.listen(5191, '127.0.0.1', () => console.log('Admin widget fixture: http://127.0.0.1:5191')); for (const signal of ['SIGINT', 'SIGTERM']) process.once(signal, () => { server.closeAllConnections(); server.close(() => process.exit(0)); });