node.js localhost https服务器不工作
亲爱的每一个人, 我试着让https服务器。。。还有这个密码。 但不起作用 在我创建key.pem之前,先为本地主机服务器创建cert.pem 像这样的代码node.js localhost https服务器不工作,node.js,https,Node.js,Https,亲爱的每一个人, 我试着让https服务器。。。还有这个密码。 但不起作用 在我创建key.pem之前,先为本地主机服务器创建cert.pem 像这样的代码 const https = require('https'); const fs = require('fs'); const options = { key: fs.readFileSync('key.pem'), cert: fs.readFileSync('cert.pem') }; https.createServer(
const https = require('https');
const fs = require('fs');
const options = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
};
https.createServer(options,(req,res)=>{
console.log('https server start');
}).listen(8080,'localhost');
这个东西在同一个文件夹里
但不是这样工作的
谢谢你和问候 您的“它不工作”图像没有显示任何错误,因此它似乎启动正常
然而,处理请求的代码实际上并没有发送回响应,这将导致请求只是“挂起”
相反,请尝试以下方法:
openssl genrsa 1024 > key.pem
openssl req -x509 -new -key key.pem > cert.pem
亲爱的罗伯特克莱普。首先谢谢你给我的答复,我在我的应用程序中修复它。真的真的真的非常感谢你有一个美好的一天!希望这有助于:
https.createServer(options, (req, res) => {
res.end('Hello, world!');
}).listen(8080, 'localhost', () => {
console.log('https server start');
});