Files
ridebus-status/artifacts/widget-admin-fixture.mjs
Zakhar Timoshenko cb1977b65f feat: add RideBus status widget integration
- Implemented StatusWidget component for embedding RideBus service status.
- Created widget-client.js for client-side interaction with the status widget.
- Developed install-widget-integrations script to automate integration into PWA, website, and admin projects.
- Introduced server-side widget rendering in widget.mjs for generating status widget HTML.
- Added comprehensive tests for widget functionality and integration.
2026-10-14 00:24:40 +03:00

18 lines
1.5 KiB
JavaScript

// 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)); });