Skip to content

Commit da4e177

Browse files
committed
Hide sample tld domains from search engines: getting DMCA notices on them
1 parent 1ffc154 commit da4e177

File tree

4 files changed

+61
-43
lines changed

4 files changed

+61
-43
lines changed

package-lock.json

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"convict": "^6.2.3",
1010
"haikunator": "^2.1.2",
1111
"handlebars": "^4.7.3",
12+
"isbot": "^5.1.18",
1213
"js-yaml": "^4.0.0",
1314
"koa": "^2.7.0",
1415
"koa-better-flash": "0.0.4",

src/routers/tldsRouter.ts

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import * as punycode from 'punycode';
2-
import Router from '@koa/router';
3-
import path from 'path';
4-
import * as wsw from 'whoisserver-world'
1+
import { isbot } from "isbot";
2+
import * as punycode from "punycode";
3+
import Router from "@koa/router";
4+
import path from "path";
5+
import * as wsw from "whoisserver-world";
56
import * as url from "url";
67
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
78

@@ -12,39 +13,44 @@ import * as domainData from "../data/domainData.js";
1213

1314
const tldsRouter = new Router();
1415

15-
tldsRouter.get('/tlds/index.html', async (ctx: any) => {
16-
16+
tldsRouter.get("/tlds/index.html", async (ctx: any) => {
1717
const tldMap = wsw.tlds();
18-
const unsortedTlds:any[] = [];
19-
Object.getOwnPropertyNames(tldMap).forEach(x => unsortedTlds.push(tldMap[x]));
20-
unsortedTlds.forEach(x => { x.unicode = punycode.toUnicode(x.tld) })
21-
const tlds = unsortedTlds.sort((a, b) => { return a.unicode.localeCompare(b.unicode) });
22-
ctx.body = await ctx.render('tlds/index.hbs', {
18+
const unsortedTlds: any[] = [];
19+
Object.getOwnPropertyNames(tldMap).forEach((x) =>
20+
unsortedTlds.push(tldMap[x])
21+
);
22+
unsortedTlds.forEach((x) => {
23+
x.unicode = punycode.toUnicode(x.tld);
24+
});
25+
const tlds = unsortedTlds.sort((a, b) => {
26+
return a.unicode.localeCompare(b.unicode);
27+
});
28+
ctx.body = await ctx.render("tlds/index.hbs", {
2329
tlds,
24-
title: 'Top Level Domains',
30+
title: "Top Level Domains",
2531
});
26-
2732
});
2833

29-
tldsRouter.get('/tlds/', async (ctx) => {
30-
ctx.redirect('/tlds/index.html');
34+
tldsRouter.get("/tlds/", async (ctx) => {
35+
ctx.redirect("/tlds/index.html");
3136
});
3237

3338
// this must come after base /tlds/ routes
34-
tldsRouter.get('/tlds/:tld', async (ctx) => {
39+
tldsRouter.get("/tlds/:tld", async (ctx) => {
3540
ctx.redirect(`${encodeURIComponent(ctx.params.tld)}/index.html`);
3641
});
3742

38-
tldsRouter.get('/tlds/:tld/', async (ctx) => {
39-
ctx.redirect('index.html');
43+
tldsRouter.get("/tlds/:tld/", async (ctx) => {
44+
ctx.redirect("index.html");
4045
});
4146

42-
tldsRouter.get('/tlds/:tld/index.html', async (ctx:any) => {
43-
47+
tldsRouter.get("/tlds/:tld/index.html", async (ctx: any) => {
4448
const tld = ctx.params.tld;
4549

4650
if (tld.startsWith("xn--")) {
47-
ctx.redirect(`/tlds/${encodeURIComponent(punycode.toUnicode(tld))}/index.html`);
51+
ctx.redirect(
52+
`/tlds/${encodeURIComponent(punycode.toUnicode(tld))}/index.html`
53+
);
4854
return;
4955
}
5056

@@ -56,28 +62,33 @@ tldsRouter.get('/tlds/:tld/index.html', async (ctx:any) => {
5662

5763
const tldInfo = wsw.tldDetails(punycode.toASCII(tld));
5864
if (!tldInfo) {
59-
ctx.flash('error', `Sorry, we don't have any info for the domain "${tld}".`)
60-
ctx.redirect("/tlds/index.html");
61-
return;
65+
ctx.flash(
66+
"error",
67+
`Sorry, we don't have any info for the domain "${tld}".`
68+
);
69+
ctx.redirect("/tlds/index.html");
70+
return;
6271
}
6372

64-
let rdapUnofficial:string|undefined;
73+
let rdapUnofficial: string | undefined;
6574
if (!tldInfo.rdap) {
6675
const rdapInfo = rdapData.get(tld);
6776
if (rdapInfo && !rdapInfo.official && rdapInfo.working) {
6877
rdapUnofficial = rdapInfo.rdap;
6978
}
7079
}
7180

72-
const sampleDomains:string[] = [];
81+
const sampleDomains: string[] = [];
7382

74-
Object.getOwnPropertyNames(tldInfo.sampleDomains).forEach(propName => {
75-
sampleDomains.push(...tldInfo.sampleDomains[propName]);
76-
});
83+
if (!isbot(ctx.get("user-agent"))) {
84+
Object.getOwnPropertyNames(tldInfo.sampleDomains).forEach((propName) => {
85+
sampleDomains.push(...tldInfo.sampleDomains[propName]);
86+
});
87+
}
7788

7889
tldInfo.unicode = punycode.toUnicode(tld);
7990

80-
ctx.body = await ctx.render('_tlds/index.hbs', {
91+
ctx.body = await ctx.render("_tlds/index.hbs", {
8192
publicSuffixes: domainData.pslTlds[tld],
8293
rdapUnofficial,
8394
sampleDomains,
@@ -86,14 +97,12 @@ tldsRouter.get('/tlds/:tld/index.html', async (ctx:any) => {
8697
});
8798
});
8899

89-
90-
91100
const tldChangeLogUI: ChangeLogUI = new ChangeLogUI(
92-
new ChangeLog(path.join(__dirname, '../../data/icann/deltas')),
93-
'/tlds/changelog/index.html',
94-
'/tlds/changelog',
95-
'ICANN TLD',
96-
'https://botsin.space/@TLDChanges',
101+
new ChangeLog(path.join(__dirname, "../../data/icann/deltas")),
102+
"/tlds/changelog/index.html",
103+
"/tlds/changelog",
104+
"ICANN TLD",
105+
"https://botsin.space/@TLDChanges"
97106
);
98107
const tldsChangeLogRouter = tldChangeLogUI.changelogRouter;
99108

views/_tlds/index.hbs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,19 @@
6868
{{/each}}
6969
</td>
7070
</tr>
71+
{{#if sampleDomains.length}}
7172
<tr>
7273
<td>Sample domains</td>
7374
<td>
74-
{{#if sampleDomains.length}}
7575
<details>
7676
<summary>{{sampleDomains.length}}</summary>
7777
{{#each sampleDomains}}
7878
<a href="https://{{this}}/">{{this}}</a><br/>
7979
{{/each}}
8080
</details>
81-
{{else}}
82-
<i>(none)</i>
83-
{{/if}}
8481
</td>
8582
</tr>
83+
{{/if}}
8684
<tr>
8785
<td>Public Suffixes</td>
8886
<td>
@@ -108,4 +106,4 @@
108106
<pre>{{toJson tld}}</pre>
109107
</details>
110108

111-
{{>below}}
109+
{{>below}}

0 commit comments

Comments
 (0)