1
0
mirror of https://github.com/uetchy/namae.git synced 2025-03-16 20:20:38 +09:00

fix: better whois impl

This commit is contained in:
uetchy 2022-06-05 17:13:54 +09:00
parent a233c24516
commit bd239acb87
4 changed files with 20 additions and 6 deletions

View File

@ -1,6 +1,6 @@
import { VercelRequest, VercelResponse } from '@vercel/node'; import { VercelRequest, VercelResponse } from '@vercel/node';
import 'cross-fetch'; import 'cross-fetch';
import whois from 'whois-json'; import whoiser from 'whoiser';
import { send, sendError } from '../../../util/http'; import { send, sendError } from '../../../util/http';
export default async function handler( export default async function handler(
@ -14,9 +14,17 @@ export default async function handler(
} }
try { try {
const response = await whois(query, { follow: 3, verbose: true }); const response = await whoiser(query, { follow: 1, timeout: 5000 });
const availability = response[0].data.domainName ? false : true; const first = Object.values<any>(response)[0];
if (first.error) {
throw new Error(`Got error while querying for ${query}: ${first.error}`);
}
try {
const availability = first['Domain Status'].length > 0 ? false : true;
send(res, { availability }); send(res, { availability });
} catch (err) {
console.log(response);
}
} catch (err: any) { } catch (err: any) {
sendError(res, err); sendError(res, err);
} }

View File

@ -37,7 +37,7 @@
"styled-components": "^5.3.5", "styled-components": "^5.3.5",
"swr": "^1.2.2", "swr": "^1.2.2",
"validator": "^13.7.0", "validator": "^13.7.0",
"whois-json": "^2.0.4" "whoiser": "^1.13.1"
}, },
"devDependencies": { "devDependencies": {
"@sentry/cli": "^1.74.2", "@sentry/cli": "^1.74.2",

View File

@ -2,7 +2,6 @@ import useFetch from 'fetch-suspense';
import React from 'react'; import React from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { FaFirefoxBrowser } from 'react-icons/fa'; import { FaFirefoxBrowser } from 'react-icons/fa';
import { RiChromeFill } from 'react-icons/ri';
import { Card, Result } from '../core'; import { Card, Result } from '../core';
const Search: React.FC<{ query: string }> = ({ query }) => { const Search: React.FC<{ query: string }> = ({ query }) => {

View File

@ -10541,6 +10541,13 @@ whois@^2.6.0:
underscore "^1.9.1" underscore "^1.9.1"
yargs "^15.4.1" yargs "^15.4.1"
whoiser@^1.13.1:
version "1.13.1"
resolved "https://registry.npmjs.org/whoiser/-/whoiser-1.13.1.tgz#943a2030199efd774d5047df22528316ac6de5de"
integrity sha512-4MF0LoIsSdM7R9rs9A+PxbCXMDRmRdF7eZb8IC8pGethCrSizqMLcbJCXZO5iZGqOKovQlRhpSFGGUlwUPzoQA==
dependencies:
punycode "^2.1.1"
wide-align@^1.1.0: wide-align@^1.1.0:
version "1.1.5" version "1.1.5"
resolved "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz#df1d4c206854369ecf3c9a4898f1b23fbd9d15d3" resolved "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz#df1d4c206854369ecf3c9a4898f1b23fbd9d15d3"