2017-09-21 5 views
0

サーバの起動時にコンソールに情報を記録したい。このようなexpress.js、どうすればhttpサーバとhttpsサーバを区別できますか?

情報:ここ

http server is started, address: http://127.0.0.1:2223

https server is started, address: https://127.0.0.1:2222

は私のコードです:

httpsServer.on('listening',() => onListening(httpsServer)); 
httpServer.on('listening',() => onListening(httpServer)); 

function onListening(server: http.Server | https.Server) { 
    const addr = server.address(); 
    let protocoal: string; 

    //Here, I want to distinguish https and http server. 
    //Is there nodeJs/express.js way rather than pass a parameter way? 
    //like `server.secure` api? 

    protocol = server.secure ? 'https' : 'http'; 

    console.log(protocoal + ' server is started,address:' + addr.address + ':' + addr.port); 
} 

答えて

2

Expressがあれば、trueとなるbooleanプロパティですreq.secureを持っているTLS接続確立されています。

+0

これはOPが尋ねたものですが、「リスニング」イベントでは利用できません。 – Paul

関連する問題