Allow IDNs on /dns/

parent f667727c
......@@ -4,6 +4,8 @@ import isDomainName from "is-domain-name";
import axios from "axios";
import getIpInfo from "../functions/getIpInfo";
import isIp from "is-ip";
import isIdn from "../functions/isIdn";
import punycode from "punycode";
const router: Router = Router();
......@@ -43,6 +45,8 @@ router.get("/:domain", (req: Request, res: Response, next: NextFunction) => {
});
})
.catch(next);
} else if(isIdn(req.params.domain)) {
res.redirect(`/dns/${punycode.toASCII(req.params.domain)}`)
} else {
next();
}
......
......@@ -46,7 +46,7 @@ router.get("/", (req: Request, res: Response, next: NextFunction) => {
resolver.resolveNs(tld)
.then(addresses => {
if(addresses.length > 2) {
res.redirect(`/tld/${tld}?from_search=true&orsq=${Buffer.from(query, 'utf8').toString('base64')}`)
res.redirect(`/tld/${tld}?from_search=true&orsq=${Buffer.from(query, 'utf8').toString('base64')}`);
}
})
.catch(err => {
......
import punycode from "punycode";
function isIdn(domain: string): boolean {
return domain !== punycode.toASCII(domain);
}
export default isIdn;
\ No newline at end of file
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