import http from 'node:http'; import fs from 'node:fs'; const fixture='Marigold'; export function createXmlServer(html=()=>fs.readFileSync('index.html','utf8')) { return http.createServer((req,res)=>{ res.setHeader('Cache-Control','no-store');res.setHeader('X-Content-Type-Options','nosniff'); if(req.method!=='GET'){res.writeHead(405);res.end('GET only');return;} const url=new URL(req.url,'http://127.0.0.1'); if(url.pathname==='/'){res.setHeader('Content-Type','text/html; charset=utf-8');res.end(html());return;} res.setHeader('Content-Type','application/xml; charset=utf-8'); if(url.pathname==='/exchange.xml'){res.end(fixture);return;} if(url.pathname==='/broken.xml'){res.end('');return;} if(url.pathname==='/slow.xml'){setTimeout(()=>{if(!res.destroyed)res.end(fixture);},300);return;} res.writeHead(404);res.end('Unknown fixture'); }); } if(process.argv[1]&&import.meta.url===new URL('file:///'+process.argv[1].replaceAll('\\','/')).href){ const server=createXmlServer();server.listen(8128,'127.0.0.1',()=>console.log('XML lab: http://127.0.0.1:8128 (Ctrl+C to stop)')); }