获取在OS X上运行的节点以响应HTTPS连接



>我有一个小节点程序。

console.log("Program Started");
var http = require('http');
//Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {      
console.log("Processing Request for URL" + request.url);
response.writeHead(200, {"Content-Type": "text/html"});
response.end("Hello World n");
});
// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000); 
console.log("Program Ended");    

如果我在MacBook上运行此程序并访问以下URL,则会看到我的Hello World消息。

http://localhost:8000/

但是,我也希望此 URL 响应 HTTPS 连接。

https://localhost:8000/

我如何使用 NodeJS 执行此操作?

本机http库可以为我执行此操作吗? 还是我需要快递?

是的,你可以简单地通过https模块来做:

1 您将必须创建证书,您可以在此处为macOS遵循此自动操作

https://stackoverflow.com/a/42298344/8395557

最新更新