mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
318c35c2cb
* Some minor implementations * Some more * Lots more * Removed 'backend' alias * removed all promises * Removed a bunch of module exports stuff * Some morE' * Fix * custom DNS * Tests for DNS * bug fix * Some small adjustments * Small stuff
27 lines
601 B
JavaScript
27 lines
601 B
JavaScript
import dns from 'dns';
|
|
import {parse as urlParse, format as urlFormat} from 'url';
|
|
|
|
function lookup (url) {
|
|
return new Promise((resolve, reject) => {
|
|
const {hostname} = urlParse(url);
|
|
dns.lookup(hostname, (err, ip) => {
|
|
err ? reject(err) : resolve(ip)
|
|
});
|
|
})
|
|
}
|
|
|
|
export async function swapHost (url) {
|
|
let ip;
|
|
|
|
try {
|
|
ip = await lookup(url);
|
|
const parsedUrl = urlParse(url);
|
|
delete parsedUrl.host; // So it doesn't build with old host
|
|
parsedUrl.hostname = ip;
|
|
return urlFormat(parsedUrl);
|
|
} catch (e) {
|
|
// Fail silently. It's OK
|
|
return url;
|
|
}
|
|
}
|