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" ;
56import * as url from "url" ;
67const __dirname = url . fileURLToPath ( new URL ( "." , import . meta. url ) ) ;
78
@@ -12,39 +13,44 @@ import * as domainData from "../data/domainData.js";
1213
1314const 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-
91100const 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) ;
98107const tldsChangeLogRouter = tldChangeLogUI . changelogRouter ;
99108
0 commit comments