axios-axios/examples/abort-controller/server.js
Kai Lee 947f7091d8
Fixes #10610 Deprecation Warning : url.parse() is deprecated in Node.… (#10625)
* Fixes #10610 Deprecation Warning : url.parse() is deprecated in Node.js v22 (via follow-redirects)

* Fixes #10610 Deprecation Warning : fixed again

* Apply suggestion from @cubic-dev-ai[bot]

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

---------

Co-authored-by: tona jose <tona00jose@gmail.com>
Co-authored-by: Jay <jasonsaayman@gmail.com>
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
2026-04-02 09:02:58 +02:00

24 lines
539 B
JavaScript

export default function (req, res) {
let parsedUrl;
try {
parsedUrl = new URL(req.url, 'http://localhost');
} catch {
res.writeHead(400, { 'Content-Type': 'text/plain' });
res.end('Invalid URL');
return;
}
const delay = parsedUrl.searchParams.get('delay') || 3000;
setTimeout(() => {
res.writeHead(200, {
'Content-Type': 'text/json',
});
res.write(
JSON.stringify({
message: 'Response completed successfully after ' + delay + 'ms',
})
);
res.end();
}, delay);
}