44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
const http = require('http');
|
|
|
|
const PORT = Number(process.env.CRANK_E2E_STREAM_FIXTURE_PORT || 3310);
|
|
|
|
function send(response, status, body) {
|
|
const payload = JSON.stringify(body);
|
|
response.writeHead(status, {
|
|
'Content-Type': 'application/json; charset=utf-8',
|
|
'Content-Length': Buffer.byteLength(payload),
|
|
'Cache-Control': 'no-store',
|
|
});
|
|
response.end(payload);
|
|
}
|
|
|
|
const server = http.createServer((request, response) => {
|
|
const url = new URL(request.url, `http://127.0.0.1:${PORT}`);
|
|
if (request.method !== 'GET') {
|
|
send(response, 405, { error: 'method_not_allowed' });
|
|
return;
|
|
}
|
|
if (url.pathname === '/health') {
|
|
send(response, 200, { status: 'ok' });
|
|
return;
|
|
}
|
|
if (url.pathname === '/rates') {
|
|
send(response, 200, {
|
|
amount: 1,
|
|
base: url.searchParams.get('base') || 'USD',
|
|
date: '2026-08-24',
|
|
rates: { EUR: 0.91 },
|
|
});
|
|
return;
|
|
}
|
|
if (url.pathname === '/upstream-error') {
|
|
send(response, 503, { error: 'fixture_upstream_unavailable' });
|
|
return;
|
|
}
|
|
send(response, 404, { error: 'fixture_not_found' });
|
|
});
|
|
|
|
server.listen(PORT, '127.0.0.1', () => {
|
|
console.log(`Playwright HTTP fixture listening on http://127.0.0.1:${PORT}`);
|
|
});
|