When redirected to TLD page by search engine, it suggests "You may search for...

When redirected to TLD page by search engine, it suggests "You may search for [query] instead" on the TLD page
parent 24e74443
......@@ -69,6 +69,11 @@ twig.extendFunction("punycodeToASCII", (input: string): string => {
return punycode.toASCII(input);
});
// https://stackabuse.com/encoding-and-decoding-base64-strings-in-node-js/
twig.extendFunction("base64Decode", (input: string): string => {
return Buffer.from(input, 'base64').toString('utf8');
})
/**
* Is server in production mode?
*/
......
......@@ -30,7 +30,9 @@ router.get("/", (req: Request, res: Response, next: NextFunction) => {
/**
* TLD check
*/
if(isDomainName(punycode.toASCII(query))) {
if(req.query.ignore_tld == "true") {
continue_search(query);
} else if(isDomainName(punycode.toASCII(query))) {
const tld = punycode.toASCII(query);
if(tld.toLowerCase() !== tld && tld.toUpperCase() !== tld) {
......@@ -44,7 +46,7 @@ router.get("/", (req: Request, res: Response, next: NextFunction) => {
resolver.resolveNs(tld)
.then(addresses => {
if(addresses.length > 2) {
res.redirect(`/tld/${tld}`)
res.redirect(`/tld/${tld}?from_search=true&orsq=${Buffer.from(query, 'utf8').toString('base64')}`)
}
})
.catch(err => {
......
......@@ -101,6 +101,9 @@ router.get("/:tld", (req: Request, res: Response, next: NextFunction) => {
"nameservers": nameservers,
"nsAddr": nameserverAddresses,
"fromSearch": req.query.from_search,
"originalSearchQuery": req.query.orsq,
});
})
.catch(catcher)
......
......@@ -3,6 +3,10 @@
{% block body %}
<h1>{{ title }}</h1>
{% if fromSearch == "true" and originalSearchQuery %}
<p>You may search for <a href="/search?q={{ base64Decode(originalSearchQuery)|e }}&amp;ignore_tld=true"><code>{{ base64Decode(originalSearchQuery)|e }}</code></a> instead.</p>
{% endif %}
{% if tldUnicode != tld %}
<p>Punycode: <code>.{{ tld }}</code></p>
{% endif %}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment