我想在服务器启动时在控制台中记录信息。
这样的信息:
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);
}