Node.js 获取运行在OS X上的节点以响应HTTPS连接
我有一个小节点程序Node.js 获取运行在OS X上的节点以响应HTTPS连接,node.js,https,Node.js,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 fo
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使用此自动证书