From 03ad607958f63883c93bd42947816e81d28efe42 Mon Sep 17 00:00:00 2001 From: fengkx Date: Tue, 21 Apr 2020 18:35:34 +0800 Subject: [PATCH] fix: protocol when srv is http2 or https Server --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 2dc4a07..44bb7b6 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,11 @@ +const tls = require('tls') + module.exports = (srv, hostname = 'localhost') => new Promise((resolve, reject) => { srv.on('error', reject) srv.listen(() => { const {port} = srv.address() - resolve(`http://${hostname}:${port}`) + const protocol = (srv instanceof tls.Server) ? 'https' : 'http' + resolve(`${protocol}://${hostname}:${port}`) }) })