[英]Node.js IPv6 issue
Node.js server is deployed on Google Cloud Platform and the server is not listening on ipv6. Node.js 服务器部署在 Google Cloud Platform 上,并且服务器不在 ipv6 上侦听。 When I run my API in a mobile browser(chrome) I am seeing this error: This site can't provide a secure connection.
当我在移动浏览器 (chrome) 中运行我的 API 时,我看到此错误:此站点无法提供安全连接。 ERR_SSL_PROTOCOL_ERROR
ERR_SSL_PROTOCOL_ERROR
How to make node.js server run on ipv6?如何让 node.js 服务器在 ipv6 上运行? Following is my code:
以下是我的代码:
const app = express();
const port = 8080;
const privateKey = fs.readFileSync(
'/path/to/privkey.pem',
'utf8'
);
const certificate = fs.readFileSync(
'/path/to/cert.pem',
'utf8'
);
const ca = fs.readFileSync(
'/path/to/chain.pem',
'utf8'
);
const options = {
key: privateKey,
cert: certificate,
ca: ca
};
https.createServer(options, app).listen(port, '::', () => {
console.log(`Server started on port ${port}`);
});
I recommend you to try this piece of code.我建议你试试这段代码。 You should be able to check it in 8082's port in localhost: https://localhost:8082/
您应该可以在本地主机的 8082 端口中检查它: https://localhost:8082/
const https = require('https');
const fs = require('fs');
const options = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
};
https.createServer(options, function (req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(8082);
Hope this helps.希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.