Skip to content

Full Toolkit for Next-Level Domain Analysis

Restructure to take advantage of RSC 🚀

Felix Wotschofskyf8d1aefd3060
diff --git a/app/api/lookupCerts/route.ts b/app/api/lookupCerts/route.ts
deleted file mode 100644
index a87ef0c..0000000
--- a/app/api/lookupCerts/route.ts
+++ /dev/null
@@ -1,74 +0,0 @@
-import isValidDomain from 'is-valid-domain';
-
-export type CertLookupResponse = {
- certificates: {
- id: number;
- issuerName: string;
- commonName: string;
- matchingIdentities: string;
- loggedAt: string;
- notBefore: string;
- notAfter: string;
- }[];
-};
-
-export const runtime = 'edge';
-
-export async function GET(request: Request) {
- const { searchParams } = new URL(request.url);
- const domain = searchParams.get('domain');
-
- if (!domain || !isValidDomain(domain || '')) {
- return new Response(
- JSON.stringify({
- error: true,
- message: '"domain" param missing or invalid',
- }),
- {
- status: 400,
- headers: {
- 'Content-Type': 'application/json',
- },
- }
- );
- }
-
- const response = await fetch(
- 'https://crt.sh?' +
- new URLSearchParams({
- Identity: domain,
- output: 'json',
- })
- );
- const data = (await response.json()) as {
- issuer_ca_id: number;
- issuer_name: string;
- common_name: string;
- name_value: string;
- id: number;
- entry_timestamp: string;
- not_before: string;
- not_after: string;
- serial_number: string;
- }[];
-
- return new Response(
- JSON.stringify({
- certificates: data.map((c) => ({
- id: c.id,
- loggedAt: c.entry_timestamp,
- notBefore: c.not_before,
- notAfter: c.not_after,
- commonName: c.common_name,
- matchingIdentities: c.name_value,
- issuerName: c.issuer_name,
- })),
- }),
- {
- status: 200,
- headers: {
- 'Content-Type': 'application/json',
- },
- }
- );
-}
diff --git a/app/api/lookupWhois/route.ts b/app/api/lookupWhois/route.ts
deleted file mode 100644
index 4e8b2fe..0000000
--- a/app/api/lookupWhois/route.ts
+++ /dev/null
@@ -1,45 +0,0 @@
-import isValidDomain from 'is-valid-domain';
-import whoiser, { type WhoisSearchResult } from 'whoiser';
-
-export type WhoisLookupResponse = {
- [domainName: string]: string;
-};
-
-export type WhoisLookupErrorResponse = { error: true; message: string };
-
-export async function GET(request: Request) {
- const { searchParams } = new URL(request.url);
- const domain = searchParams.get('domain');
-
- if (!domain || !isValidDomain(domain)) {
- return new Response(
- JSON.stringify({
- error: true,
- message: '"domain" param missing or invalid',
- }),
- {
- status: 400,
- headers: {
- 'Content-Type': 'application/json',
- },
- }
- );
- }
-
- const result = await whoiser(domain, {
- raw: true,
- timeout: 3000,
- });
-
- const mappedResults: Record<string, string> = {};
- for (const key in result) {
- mappedResults[key] = (result[key] as WhoisSearchResult).__raw as string;
- }
-
- return new Response(JSON.stringify(mappedResults), {
- status: 200,
- headers: {
- 'Content-Type': 'application/json',
- },
- });
-}
diff --git a/app/layout.tsx b/app/layout.tsx
index a759c54..c68d8a6 100644
--- a/app/layout.tsx
+++ b/app/layout.tsx
@@ -8,11 +8,11 @@ import Header from '@/components/Header';
import './globals.css';
-// export const metadata = {
-// title: 'Domain Digger',
-// };
+type RootLayoutProps = {
+ children: ReactNode;
+};
-const RootLayout = ({ children }: { children: ReactNode }) => {
+const RootLayout = ({ children }: RootLayoutProps) => {
return (
<html lang="en">
<body>
diff --git a/app/lookup/[domain]/certs/error.tsx b/app/lookup/[domain]/certs/error.tsx
new file mode 100644
index 0000000..91c22cc
--- /dev/null
+++ b/app/lookup/[domain]/certs/error.tsx
@@ -0,0 +1,9 @@
+'use client';
+
+const CertsError = () => (
+ <div className="flex items-center justify-center">
+ <p className="my-8">An error occurred!</p>
+ </div>
+);
+
+export default CertsError;
diff --git a/app/lookup/[domain]/certs/loading.tsx b/app/lookup/[domain]/certs/loading.tsx
new file mode 100644
index 0000000..f689322
--- /dev/null
+++ b/app/lookup/[domain]/certs/loading.tsx
@@ -0,0 +1,9 @@
+import { Spinner } from '@/components/ui/spinner';
+
+const CertsLoading = () => (
+ <div className="flex items-center justify-center">
+ <Spinner className="my-8" />
+ </div>
+);
+
+export default CertsLoading;
diff --git a/components/CertInfo.tsx b/app/lookup/[domain]/certs/page.tsx
similarity index 71%
rename from components/CertInfo.tsx
rename to app/lookup/[domain]/certs/page.tsx
index 800a3c2..9ff32c9 100644
--- a/components/CertInfo.tsx
+++ b/app/lookup/[domain]/certs/page.tsx
@@ -1,11 +1,6 @@
-'use client';
-
import { ExternalLinkIcon } from 'lucide-react';
import Link from 'next/link';
-import type { FC } from 'react';
-import useSWR from 'swr';
-import { Spinner } from '@/components/ui/spinner';
import {
Table,
TableBody,
@@ -20,30 +15,54 @@ import {
TooltipTrigger,
} from '@/components/ui/tooltip';
-import type { CertLookupResponse } from '@/app/api/lookupCerts/route';
+const lookupCerts = async (domain: string) => {
+ const response = await fetch(
+ 'https://crt.sh?' +
+ new URLSearchParams({
+ Identity: domain,
+ output: 'json',
+ })
+ );
+
+ if (!response.ok) {
+ throw new Error('Failed to fetch certs');
+ }
+
+ const data = (await response.json()) as {
+ issuer_ca_id: number;
+ issuer_name: string;
+ common_name: string;
+ name_value: string;
+ id: number;
+ entry_timestamp: string;
+ not_before: string;
+ not_after: string;
+ serial_number: string;
+ }[];
-type CertInfoProps = {
- domain: string;
+ return data.map((c) => ({
+ id: c.id,
+ loggedAt: c.entry_timestamp,
+ notBefore: c.not_before,
+ notAfter: c.not_after,
+ commonName: c.common_name,
+ matchingIdentities: c.name_value,
+ issuerName: c.issuer_name,
+ }));
};
-const CertInfo: FC<CertInfoProps> = ({ domain }) => {
- const { data, error } = useSWR<CertLookupResponse>(
- `/api/lookupCerts?domain=${encodeURIComponent(domain)}`
- );
+type CertsResultsPageProps = {
+ params: { domain: string };
+};
- if (!data) {
- return (
- <div className="flex items-center justify-center">
- <Spinner className="my-8" />
- </div>
- );
- }
+export const runtime = 'edge';
- if (error) {
- return <p>An error occurred!</p>;
- }
+const CertsResultsPage = async ({
+ params: { domain },
+}: CertsResultsPageProps) => {
+ const certs = await lookupCerts(domain);
- if (!data.certificates.length) {
+ if (!certs.length) {
return (
<p className="mt-8 text-center text-muted-foreground">
No issued certificates found!
@@ -64,7 +83,7 @@ const CertInfo: FC<CertInfoProps> = ({ domain }) => {
</TableRow>
</TableHead>
<TableBody>
- {data.certificates.map((cert) => (
+ {certs.map((cert) => (
<TableRow key={cert.id}>
<TableCell className="pl-0">{cert.loggedAt}</TableCell>
<TableCell>{cert.notBefore}</TableCell>
@@ -114,4 +133,4 @@ const CertInfo: FC<CertInfoProps> = ({ domain }) => {
);
};
-export default CertInfo;
+export default CertsResultsPage;
diff --git a/app/lookup/[domain]/layout.tsx b/app/lookup/[domain]/layout.tsx
new file mode 100644
index 0000000..994a5c4
--- /dev/null
+++ b/app/lookup/[domain]/layout.tsx
@@ -0,0 +1,44 @@
+import { ExternalLinkIcon } from 'lucide-react';
+import type { FC, ReactNode } from 'react';
+
+import RelatedDomains from '@/components/RelatedDomains';
+import ResultsTabs from '@/components/ResultsTabs';
+import SearchForm from '@/components/SearchForm';
+
+type LookupLayoutProps = {
+ children: ReactNode;
+ params: {
+ domain: string;
+ };
+};
+
+const LookupLayout: FC<LookupLayoutProps> = ({
+ children,
+ params: { domain },
+}) => {
+ return (
+ <>
+ <title>{`Results for ${domain} - Domain Digger`}</title>
+
+ <div className="container mb-8 max-w-xl">
+ <SearchForm initialValue={domain} />
+ </div>
+
+ <div className="container">
+ <h1 className="mb-2 text-4xl font-bold">
+ Results for{' '}
+ <a href={`https://${domain}`} target="_blank">
+ {domain} <ExternalLinkIcon className="inline-block" />
+ </a>
+ </h1>
+
+ <RelatedDomains domain={domain} />
+ <ResultsTabs domain={domain} />
+
+ {children}
+ </div>
+ </>
+ );
+};
+
+export default LookupLayout;
diff --git a/app/lookup/[domain]/page.tsx b/app/lookup/[domain]/page.tsx
index 2d2c6b9..fea1317 100644
--- a/app/lookup/[domain]/page.tsx
+++ b/app/lookup/[domain]/page.tsx
@@ -1,19 +1,24 @@
-import LookupPageContent from '@/components/LookupPageContent';
+import DnsTable from '@/components/DnsTable';
import DnsLookup from '@/utils/DnsLookup';
-const LookupDomain = async ({
- params: { domain },
-}: {
+type LookupDomainProps = {
params: { domain: string };
-}) => {
+};
+
+const LookupDomain = async ({ params: { domain } }: LookupDomainProps) => {
const records = await DnsLookup.resolveAllRecords(domain);
return (
<>
- <title>{`Results for ${domain} - Domain Digger`}</title>
-
- {/* Temporary workaround until Chakra hopefully supports server components */}
- <LookupPageContent domain={domain} records={records} />
+ {Object.values(records)
+ .map((r) => r.length)
+ .reduce((prev, curr) => prev + curr, 0) === 0 ? (
+ <p className="mt-8 text-center text-muted-foreground">
+ No DNS records found!
+ </p>
+ ) : (
+ <DnsTable records={records} />
+ )}
</>
);
};
diff --git a/app/lookup/[domain]/whois/error.tsx b/app/lookup/[domain]/whois/error.tsx
new file mode 100644
index 0000000..33bec24
--- /dev/null
+++ b/app/lookup/[domain]/whois/error.tsx
@@ -0,0 +1,9 @@
+'use client';
+
+const WhoisError = () => (
+ <div className="flex items-center justify-center">
+ <p className="my-8">An error occurred!</p>
+ </div>
+);
+
+export default WhoisError;
diff --git a/app/lookup/[domain]/whois/loading.tsx b/app/lookup/[domain]/whois/loading.tsx
new file mode 100644
index 0000000..896c5e4
--- /dev/null
+++ b/app/lookup/[domain]/whois/loading.tsx
@@ -0,0 +1,9 @@
+import { Spinner } from '@/components/ui/spinner';
+
+const WhoisLoading = () => (
+ <div className="flex items-center justify-center">
+ <Spinner className="my-8" />
+ </div>
+);
+
+export default WhoisLoading;
diff --git a/app/lookup/[domain]/whois/page.tsx b/app/lookup/[domain]/whois/page.tsx
new file mode 100644
index 0000000..2ac7693
--- /dev/null
+++ b/app/lookup/[domain]/whois/page.tsx
@@ -0,0 +1,39 @@
+import { Fragment } from 'react';
+import whoiser, { type WhoisSearchResult } from 'whoiser';
+
+const lookupWhois = async (domain: string) => {
+ const result = await whoiser(domain, {
+ raw: true,
+ timeout: 3000,
+ });
+
+ const mappedResults: Record<string, string> = {};
+ for (const key in result) {
+ mappedResults[key] = (result[key] as WhoisSearchResult).__raw as string;
+ }
+
+ return mappedResults;
+};
+
+type WhoisResultsPageProps = {
+ params: { domain: string };
+};
+
+const WhoisResultsPage = async ({
+ params: { domain },
+}: WhoisResultsPageProps) => {
+ const data = await lookupWhois(domain);
+
+ return (
+ <>
+ {Object.keys(data).map((key) => (
+ <Fragment key={key}>
+ <h2 className="mb-4 mt-8 text-3xl font-bold tracking-tight">{key}</h2>
+ <code className="whitespace-pre-wrap">{data[key]}</code>
+ </Fragment>
+ ))}
+ </>
+ );
+};
+
+export default WhoisResultsPage;
diff --git a/components/LookupPageContent.tsx b/components/LookupPageContent.tsx
deleted file mode 100644
index 61802d4..0000000
--- a/components/LookupPageContent.tsx
+++ /dev/null
@@ -1,67 +0,0 @@
-'use client';
-
-import { ExternalLinkIcon } from 'lucide-react';
-import type { FC } from 'react';
-
-import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
-
-import CertInfo from '@/components/CertInfo';
-import DnsTable from '@/components/DnsTable';
-import RelatedDomains from '@/components/RelatedDomains';
-import SearchForm from '@/components/SearchForm';
-import WhoisInfo from '@/components/WhoisInfo';
-import type { ResolvedRecords } from '@/utils/DnsLookup';
-
-type LookupPageContentProps = {
- domain: string;
- records: ResolvedRecords;
-};
-
-const LookupPageContent: FC<LookupPageContentProps> = ({ domain, records }) => (
- <>
- <div className="container mb-8 max-w-xl">
- <SearchForm initialValue={domain} />
- </div>
-
- <div className="container">
- <h1 className="mb-2 text-4xl font-bold">
- Results for{' '}
- <a href={`https://${domain}`} target="_blank">
- {domain} <ExternalLinkIcon className="inline-block" />
- </a>
- </h1>
-
- <RelatedDomains domain={domain} />
-
- <Tabs defaultValue="dns" className="mt-6">
- <TabsList>
- <TabsTrigger value="dns">DNS</TabsTrigger>
- <TabsTrigger value="whois">Whois</TabsTrigger>
- <TabsTrigger value="certs">Certs</TabsTrigger>
- </TabsList>
-
- <TabsContent value="dns">
- {Object.values(records)
- .map((r) => r.length)
- .reduce((prev, curr) => prev + curr, 0) === 0 ? (
- <p className="mt-8 text-center text-muted-foreground">
- No DNS records found!
- </p>
- ) : (
- <DnsTable records={records} />
- )}
- </TabsContent>
-
- <TabsContent value="whois">
- <WhoisInfo domain={domain} />
- </TabsContent>
-
- <TabsContent value="certs">
- <CertInfo domain={domain} />
- </TabsContent>
- </Tabs>
- </div>
- </>
-);
-
-export default LookupPageContent;
diff --git a/components/RelatedDomains.tsx b/components/RelatedDomains.tsx
index 69a88be..22fdadf 100644
--- a/components/RelatedDomains.tsx
+++ b/components/RelatedDomains.tsx
@@ -1,3 +1,5 @@
+'use client';
+
import Link from 'next/link';
import type { FC } from 'react';
@@ -21,7 +23,7 @@ const RelatedDomains: FC<RelatedDomainsProps> = ({ domain: original }) => {
}
return (
- <div className="flex gap-4">
+ <div className="mb-4 mt-2 flex gap-4">
{domains.map((domain) => (
<Button
key={domain}
diff --git a/components/ResultsTabs.tsx b/components/ResultsTabs.tsx
new file mode 100644
index 0000000..54f7a0c
--- /dev/null
+++ b/components/ResultsTabs.tsx
@@ -0,0 +1,60 @@
+'use client';
+
+import Link from 'next/link';
+import { useSelectedLayoutSegment } from 'next/navigation';
+import { FC } from 'react';
+
+type ResultsTabsProps = {
+ domain: string;
+};
+
+const ResultsTabs: FC<ResultsTabsProps> = ({ domain }) => {
+ const selectedSegment = useSelectedLayoutSegment();
+
+ return (
+ <div className="mt-6 border-b border-gray-200 text-center text-sm font-medium text-gray-500 dark:border-gray-700 dark:text-gray-400">
+ <ul className="-mb-px flex flex-wrap">
+ <li className="mr-2">
+ <Link
+ href={`/lookup/${domain}`}
+ className={
+ selectedSegment === null
+ ? 'inline-block rounded-t-lg border-b-2 border-primary p-4 text-primary'
+ : 'inline-block rounded-t-lg border-b-2 border-transparent p-4 hover:border-gray-300 hover:text-gray-600 dark:hover:text-gray-300'
+ }
+ >
+ DNS
+ </Link>
+ </li>
+ <li className="mr-2">
+ <Link
+ href={`/lookup/${domain}/whois`}
+ className={
+ selectedSegment === 'whois'
+ ? 'inline-block rounded-t-lg border-b-2 border-primary p-4 text-primary'
+ : 'inline-block rounded-t-lg border-b-2 border-transparent p-4 hover:border-gray-300 hover:text-gray-600 dark:hover:text-gray-300'
+ }
+ aria-current="page"
+ >
+ Whois
+ </Link>
+ </li>
+ <li className="mr-2">
+ <Link
+ href={`/lookup/${domain}/certs`}
+ className={
+ selectedSegment === 'certs'
+ ? 'inline-block rounded-t-lg border-b-2 border-primary p-4 text-primary'
+ : 'inline-block rounded-t-lg border-b-2 border-transparent p-4 hover:border-gray-300 hover:text-gray-600 dark:hover:text-gray-300'
+ }
+ aria-current="page"
+ >
+ Certs
+ </Link>
+ </li>
+ </ul>
+ </div>
+ );
+};
+
+export default ResultsTabs;
diff --git a/components/WhoisInfo.tsx b/components/WhoisInfo.tsx
deleted file mode 100644
index 326ceb9..0000000
--- a/components/WhoisInfo.tsx
+++ /dev/null
@@ -1,43 +0,0 @@
-'use client';
-
-import { type FC, Fragment } from 'react';
-import useSWR from 'swr';
-
-import { Spinner } from '@/components/ui/spinner';
-
-import type { WhoisLookupResponse } from '@/app/api/lookupWhois/route';
-
-type IpDetailsModalProps = {
- domain: string;
-};
-
-const WhoisModal: FC<IpDetailsModalProps> = ({ domain }) => {
- const { data, error } = useSWR<WhoisLookupResponse>(
- `/api/lookupWhois?domain=${encodeURIComponent(domain)}`
- );
-
- if (!data) {
- return (
- <div className="items-cen flex justify-center">
- <Spinner className="my-8" />
- </div>
- );
- }
-
- if (error) {
- return <p>An error occurred!</p>;
- }
-
- return (
- <>
- {Object.keys(data).map((key) => (
- <Fragment key={key}>
- <h2 className="mb-4 mt-8 text-3xl font-bold tracking-tight">{key}</h2>
- <code className="whitespace-pre-wrap">{data[key]}</code>
- </Fragment>
- ))}
- </>
- );
-};
-
-export default WhoisModal;
diff --git a/next-env.d.ts b/next-env.d.ts
index fd36f94..4f11a03 100644
--- a/next-env.d.ts
+++ b/next-env.d.ts
@@ -1,6 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
-/// <reference types="next/navigation-types/compat/navigation" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.