-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
714af61
commit 0529f30
Showing
11 changed files
with
160 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import Handlebars from 'handlebars'; | ||
import KoaRouter from 'koa-router'; | ||
import path from 'path'; | ||
import * as psl from 'psl'; | ||
|
||
import { ChangeLog } from '../changelog'; | ||
import { ChangeLogUI } from '../ChangeLogUI'; | ||
import * as domainData from '../data/domainData'; | ||
|
||
const pslRouter = new KoaRouter(); | ||
|
||
pslRouter.get('/psl/', async (ctx: any) => { | ||
ctx.redirect(ctx, '/psl/index.html'); | ||
}); | ||
|
||
|
||
pslRouter.get('/psl/index.html', async (ctx: any) => { | ||
|
||
ctx.body = await ctx.render('psl/index.hbs', { | ||
domains: Object.keys(domainData.pslTlds).sort((a, b) => { return a.localeCompare(b); }), | ||
psl: domainData.pslTlds, | ||
title: 'Public Suffix List Top Level Domains', | ||
total: Object.values(domainData.pslTlds).reduce((acc, val) => acc + val.length, 0), | ||
}); | ||
}); | ||
|
||
pslRouter.get('/psl/test.html', async (ctx: any) => { | ||
|
||
const q = ctx.request.query.q; | ||
const hostname = q; | ||
let get: string | null | undefined; | ||
let parsed: psl.ParsedDomain | psl.ParseError | null | undefined; | ||
if (hostname) { | ||
if (!psl.isValid(hostname)) { | ||
ctx.flash('error', `${Handlebars.escapeExpression(hostname)} is not a valid public domain!`); | ||
} else { | ||
get = psl.get(hostname); | ||
parsed = psl.parse(hostname); | ||
|
||
if (parsed.error) { | ||
ctx.flash('error', `${parsed.error.message} for ${Handlebars.escapeExpression(hostname)}`); | ||
parsed = null; | ||
} | ||
} | ||
} | ||
|
||
ctx.body = await ctx.render('psl/test.hbs', { | ||
examples: ['test.github.io', 'github.io'], | ||
get, | ||
parsed, | ||
q, | ||
title: 'Public Suffix Test', | ||
}); | ||
}); | ||
|
||
const pslChangeLogUI:ChangeLogUI = new ChangeLogUI( | ||
new ChangeLog(path.join(__dirname, '../../data/publicsuffix/deltas')), | ||
'/psl/index.html', | ||
'/psl/changelog', | ||
'Public Suffix List', | ||
'https://botsin.space/@PublicSuffixChanges', | ||
); | ||
const pslChangeLogRouter = pslChangeLogUI.changelogRouter; | ||
const pslChangeLogGetUrls = pslChangeLogUI.getUrls; | ||
|
||
export { | ||
pslRouter, | ||
pslChangeLogRouter, | ||
pslChangeLogGetUrls, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.