问题
Node.js server is deployed on Google Cloud Platform and the server is not listening on ipv6. When I run my API in a mobile browser(chrome) I am seeing this error: This site can't provide a secure connection. ERR_SSL_PROTOCOL_ERROR
How to make node.js server run on 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}`);
});
回答1:
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/
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.
来源:https://stackoverflow.com/questions/59136690/node-js-ipv6-issue