* HTTPS Server는 HTTP Server와 유사하게 이용 가능하다. 앞의 TLS 처럼 options 값을 주고 https 모듈을 이용하면 된다.
var fs=require('fs'); var https=require('https'); var options={ key:fs.readFileSync('./server_key.pem'), cert:fs.readFileSync('./server_cert.pem'), ca:fs.readFileSync('./client_cert.pem'), requestCert:true, rejectUnauthorized:true }; var server=https.createServer(options,function(req,res){ res.writeHead(200,{'Content-Type':'text/plain'}); res.end('Hello World'); console.log('authorized:',req.socket.authorized); console.log('client certificate:',req.socket.getPeerCertificate()); }); var port=4001; var address='192.168.0.80'; server.listen(port,address,function(){ console.log('Server is listening on port',server.address().port); }); |
var fs=require('fs'); var https=require('https'); var options={ host:'google.com', method:'GET', path:'/' }; var request=https.request(options,function(res){ console.log('authorized:',res.socket.authorized); console.log('certificate:',res.socket.getPeerCertificate()); }); request.end(); |