import valTownBadgeMiddleware from "https://esm.town/v/jxnblk/valTownBadgeMiddleware?v=10";
import { Hono } from "npm:hono";
const app = new Hono();
export default valTownBadgeMiddleware(app.fetch, import.meta.url);
app.get("/", (c) => {
return c.html(
<html>
<head>
<title>DNS Lookup Tool</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="icon" href="https://fav.farm/๐" />
</head>
<body class="p-4">
<h1 class="text-3xl font-bold underline">DNS Lookup Tool</h1>
<form method="get" action="/dns-lookup" class="mt-4">
<label class="block mb-2">
Domain name:
<input type="text" name="domain" class="border p-2 w-full" />
</label>
<button type="submit" class="bg-blue-500 text-white py-2 px-4 rounded">
Check DNS
</button>
</form>
</body>
</html>,
);
});
app.get("/dns-lookup", async (c) => {
const domain = c.req.query("domain");
const results = await Promise.all([
"A",
"AAAA",
"MX",
"NS",
"CNAME",
"SOA",
"TXT",
].map(async record => [record, await Deno.resolveDns(domain, record).catch(e => e.toString())]));
return c.html(
<html>
<head>
<title>DNS Lookup Result</title>
<link rel="icon" href="https://fav.farm/๐" />
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="p-4">
<h1 class="text-3xl font-bold underline">DNS Lookup Results for {domain}</h1>
{results.map(([recordType, entries]) => (
<div class="my-4">
<h2 class="text-xl fold-bold">{recordType}</h2>
<ul>
{entries.map ? entries.map(entry => <li>{entry}</li>) : entries}
</ul>
</div>
))}
<div class="mt-4">
<a
href="/"
class="bg-blue-500 text-white py
-2 px-4 rounded"
>
Back
</a>
</div>
</body>
</html>,
);
});