I'm developing a web-app on a cyrillic domain. Currently, this domain hosts a "parked page", saying the site is under construction. If I access it in Chrome, I see punycode in the address bar. Safari decodes it, though. For the development purposes, I have modified my /etc/hosts
file to be able to access localhost via a test cyrillic domain. However, both Chrome and Safari fail to decode the hostname.
I have looked up this issue, but could not find any sensible solution. There is a module for Node.js called punycode
. Now, if my req.url
contains cyrillic characters, it gets URIComponent
-encoded, hence I've written a middleware to decode it:
app.use(function(req, res, next) {
var url = req.url,
decoded = decodeURIComponent(url);
if (url !== decoded) req.url = decoded;
next();
});
It works fine, I can use cyrillic routing now. But when I try to apply this logic to hostname, it doesn't work:
app.use(function(req, res, next) {
var hostname = req.hostname,
decoded = punycode.toUnicode(hostname);
if (hostname !== decoded) req.hostname = decoded;
// I have also tried return res.redirect('https://' + decoded + ':' + ...);
next();
});
Any help is very much appreciated. Thanks!