Skip to content

Commit 4718b74

Browse files
committed
refactor: avoid new public options on class
1 parent 199baec commit 4718b74

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

lib/Server.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -636,20 +636,20 @@ class Server {
636636
let networkUrlIPv4;
637637
let networkUrlIPv6;
638638

639-
if (this.hostname) {
640-
if (this.hostname === 'localhost') {
639+
if (this.options.host) {
640+
if (this.options.host === 'localhost') {
641641
localhost = prettyPrintUrl('localhost');
642642
} else {
643643
let isIP;
644644

645645
try {
646-
isIP = ipaddr.parse(this.hostname);
646+
isIP = ipaddr.parse(this.options.host);
647647
} catch (error) {
648648
// Ignore
649649
}
650650

651651
if (!isIP) {
652-
server = prettyPrintUrl(this.hostname);
652+
server = prettyPrintUrl(this.options.host);
653653
}
654654
}
655655
}
@@ -744,21 +744,22 @@ class Server {
744744
}
745745

746746
if (this.options.open) {
747-
const openTarget = prettyPrintUrl(this.hostname || 'localhost');
747+
const openTarget = prettyPrintUrl(this.options.host || 'localhost');
748748

749749
runOpen(openTarget, this.options.open, this.logger);
750750
}
751751
}
752752

753753
listen(port, hostname, fn) {
754754
if (hostname === 'local-ip') {
755-
this.hostname = internalIp.v4.sync() || internalIp.v6.sync() || '0.0.0.0';
755+
this.options.host =
756+
internalIp.v4.sync() || internalIp.v6.sync() || '0.0.0.0';
756757
} else if (hostname === 'local-ipv4') {
757-
this.hostname = internalIp.v4.sync() || '0.0.0.0';
758+
this.options.host = internalIp.v4.sync() || '0.0.0.0';
758759
} else if (hostname === 'local-ipv6') {
759-
this.hostname = internalIp.v6.sync() || '::';
760+
this.options.host = internalIp.v6.sync() || '::';
760761
} else {
761-
this.hostname = hostname;
762+
this.options.host = hostname;
762763
}
763764

764765
if (typeof port !== 'undefined' && port !== this.options.port) {
@@ -773,7 +774,7 @@ class Server {
773774
.then((port) => {
774775
this.options.port = port;
775776

776-
return this.server.listen(port, this.hostname, (error) => {
777+
return this.server.listen(port, this.options.host, (error) => {
777778
if (this.options.hot || this.options.liveReload) {
778779
this.createSocketServer();
779780
}
@@ -903,12 +904,12 @@ class Server {
903904
// these are removed from the hostname in url.parse(),
904905
// so we have the pure IPv6-address in hostname.
905906
// always allow localhost host, for convenience (hostname === 'localhost')
906-
// allow hostname of listening address (hostname === this.hostname)
907+
// allow hostname of listening address (hostname === this.options.host)
907908
const isValidHostname =
908909
ipaddr.IPv4.isValid(hostname) ||
909910
ipaddr.IPv6.isValid(hostname) ||
910911
hostname === 'localhost' ||
911-
hostname === this.hostname;
912+
hostname === this.options.host;
912913

913914
if (isValidHostname) {
914915
return true;

0 commit comments

Comments
 (0)