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

chore: print network url by default #2078

Merged
merged 3 commits into from
Feb 3, 2025
Merged
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
19 changes: 10 additions & 9 deletions examples/arco-pro/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ describe(`e2e tests - ${name}`, async () => {

// browser HMR should work
if (command === 'start') {
const filePath = fileURLToPath(
path.join(
path.dirname(import.meta.url),
'src',
'pages',
'dashboard',
'workplace',
'docs.tsx'
)
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const filePath = path.join(
__dirname,
'src',
'pages',
'dashboard',
'workplace',
'docs.tsx'
);

const content = readFileSync(filePath, 'utf-8');
writeFileSync(
filePath,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ export class Server extends httpServer {
this.config.compilation.define.FARM_HMR_PORT = serverPort.toString();

this.resolvedUrls = await resolveServerUrls(this.httpServer, this.config);

// compile the project and start the dev server
await this.#startCompile();

Expand Down
62 changes: 24 additions & 38 deletions packages/core/src/utils/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,43 +56,30 @@ export async function resolveServerUrls(
const port = address.port;
const base = config.compilation.output.publicPath;

if (hostname.host !== undefined && !wildcardHosts.has(hostname.host)) {
let hostnameName = hostname.name;
// ipv6 host
if (hostnameName.includes(':')) {
hostnameName = `[${hostnameName}]`;
}
const address = `${protocol}://${hostnameName}:${port}${base}`;
if (loopbackHosts.has(hostname.host)) {
local.push(address);
} else {
network.push(address);
}
} else {
Object.values(os.networkInterfaces())
.flatMap((nInterface) => nInterface ?? [])
.filter(
(detail) =>
detail &&
detail.address &&
(detail.family === 'IPv4' ||
// @ts-expect-error Node 18.0 - 18.3 returns number
detail.family === 4)
)
.forEach((detail) => {
let host = detail.address.replace('127.0.0.1', hostname.name);
// ipv6 host
if (host.includes(':')) {
host = `[${host}]`;
}
const url = `${protocol}://${host}:${port}${base}`;
if (detail.address.includes('127.0.0.1')) {
local.push(url);
} else {
network.push(url);
}
});
}
// print all network interfaces networkInterfaces() by default
Object.values(os.networkInterfaces())
.flatMap((nInterface) => nInterface ?? [])
.filter(
(detail) =>
detail &&
detail.address &&
(detail.family === 'IPv4' ||
// @ts-expect-error Node 18.0 - 18.3 returns number
detail.family === 4)
)
.forEach((detail) => {
let host = detail.address.replace('127.0.0.1', hostname.name);
// ipv6 host
if (host.includes(':')) {
host = `[${host}]`;
}
const url = `${protocol}://${host}:${port}${base}`;
if (detail.address.includes('127.0.0.1')) {
local.push(url);
} else {
network.push(url);
}
});
return { local, network };
}

Expand All @@ -114,7 +101,6 @@ export async function resolveHostname(
let name = host === undefined || wildcardHosts.has(host) ? 'localhost' : host;

if (host === 'localhost') {
// See #8647 for more details.
const localhostAddr = await getLocalhostAddressIfDiffersFromDNS();
if (localhostAddr) {
name = localhostAddr;
Expand Down
Loading