Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added server url logging at the end #5366

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2870,6 +2870,29 @@ class Server {
const useColor = getColorsOption(this.getCompilerOptions());

const server = /** @type {S} */ (this.server);
const logServerUrls = () => {
const protocol = this.isTlsServer ? "https" : "http";
const { address, port } =
/** @type {import("net").AddressInfo} */ (server.address());

const prettyPrintURL = (hostname) =>
url.format({ protocol, hostname, port, pathname: "/" });

const localhost = prettyPrintURL("localhost");
const networkIPv4 = Server.findIp("v4", false)
? prettyPrintURL(Server.findIp("v4", false))
: null;

this.logger.info(`Project is running at:`);

if (localhost) {
this.logger.info(`- Local: ${colors.info(useColor, localhost)}`);
}

if (networkIPv4) {
this.logger.info(`- On Your Network: ${colors.info(useColor, networkIPv4)}`);
}
};

if (this.options.ipc) {
this.logger.info(`Project is running at: "${server.address()}"`);
Expand Down Expand Up @@ -2962,6 +2985,8 @@ class Server {
loopbacks.push([colors.info(useColor, localhost)]);
}



if (loopbackIPv4) {
loopbacks.push([colors.info(useColor, loopbackIPv4)]);
}
Expand All @@ -2979,12 +3004,17 @@ class Server {
);
}

this.compiler.hooks.done.tap("LogServerUrlsPlugin", () => {
logServerUrls();
});

if (networkUrlIPv6) {
this.logger.info(
`On Your Network (IPv6): ${colors.info(useColor, networkUrlIPv6)}`,
);
}


if (/** @type {NormalizedOpen[]} */ (this.options.open).length > 0) {
const openTarget = prettyPrintURL(
!this.options.host ||
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"node": ">= 18.12.0"
},
"scripts": {
"start":"webpack serve --config webpack.config.js",
"fmt:check": "prettier \"{**/*,*}.{js,json,md,yml,css,ts}\" --list-different",
"lint:prettier": "prettier --cache --list-different .",
"lint:js": "eslint --cache .",
Expand Down