2017-03-03 82 views
0
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'); 

尊敬的各位之一, 我試圖讓HTTPS服務器......這個代碼。 但不工作。的node.js本地主機HTTPS服務器無法正常工作什麼

之前,我做到key.pem,cert.pem本地主機服務器

這樣的代碼

openssl genrsa 1024 > key.pem 
openssl req -x509 -new -key key.pem > cert.pem 

和這件事情在同一文件夾

但不是這樣工作enter image description here

謝謝,並關心。

回答

1

你的「它不工作」的圖像沒有顯示任何錯誤,所以它似乎啓動得很好。

但是,處理請求的代碼實際上並沒有發送迴應,這會導致請求「掛起」。

相反,試試這個:

https.createServer(options, (req, res) => { 
    res.end('Hello, world!'); 
}).listen(8080, 'localhost',() => { 
    console.log('https server start'); 
}); 
+0

親愛robertklep。首先感謝你的答案~~~~對我來說,我修復了我的應用程序。真的非常感謝你有美好的一天! –

相關問題