Skip to content

Commit 54ea712

Browse files
committed
refactor: code
1 parent 52d9587 commit 54ea712

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

lib/Server.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -751,13 +751,10 @@ class Server {
751751
}
752752

753753
listen(port, hostname, fn) {
754-
if (hostname === 'local-ip') {
755-
this.options.host =
756-
internalIp.v4.sync() || internalIp.v6.sync() || '0.0.0.0';
757-
} else if (hostname === 'local-ipv4') {
758-
this.options.host = internalIp.v4.sync() || '0.0.0.0';
759-
} else if (hostname === 'local-ipv6') {
760-
this.options.host = internalIp.v6.sync() || '::';
754+
if (typeof hostname !== 'undefined' && hostname !== this.options.host) {
755+
throw new Error(
756+
'The host specified in options is different from the host passed as an argument.'
757+
);
761758
}
762759

763760
if (typeof port !== 'undefined' && port !== this.options.port) {
@@ -766,10 +763,15 @@ class Server {
766763
);
767764
}
768765

769-
if (typeof hostname !== 'undefined' && hostname !== this.options.host) {
770-
throw new Error(
771-
'The host specified in options is different from the host passed as an argument.'
772-
);
766+
if (hostname === 'local-ip') {
767+
this.options.host =
768+
internalIp.v4.sync() || internalIp.v6.sync() || '0.0.0.0';
769+
} else if (hostname === 'local-ipv4') {
770+
this.options.host = internalIp.v4.sync() || '0.0.0.0';
771+
} else if (hostname === 'local-ipv6') {
772+
this.options.host = internalIp.v6.sync() || '::';
773+
} else {
774+
this.options.host = hostname;
773775
}
774776

775777
return (

0 commit comments

Comments
 (0)