При создании сервера на node.js в качестве hostname можно было указать 0.0.0.0
, чтобы к созданному серверу можно было обратиться по любому адресу. Какой адрес обладает аналогичным предназначением в протоколе ip v6?
const http = require('http');
const util = require('util');
function startServer(hostname, port) {
const server = http.createServer((req, res) => {
console.log(req.url);
console.log(util.format(new Date).replace(/[-:.]/g, '_'));
console.log(req.method);
console.log(req.connection.remoteAddress);
console.log(`handled by: ${hostname}`);
console.log('===');
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end(`hostname: ${hostname}\nport: ${port}`);
});
server.listen(port, hostname, () => {
console.log(`Started:\nhostname: ${hostname}\nport: ${port}\n===\n`);
});
}
startServer('0.0.0.0', 8080); // Любой внешний адрес
startServer('::1', 8080); // Только http://[::1]:8080/ и http://localhost:8080
::
?