log-listening-on.ts — astro Source File
Architecture documentation for log-listening-on.ts, a typescript file in the astro codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR f924c5ec_b86a_e284_c9c3_d5d9b3562d39["log-listening-on.ts"] c2f6615e_96e9_c4eb_5f71_cf120e271705["node:http"] f924c5ec_b86a_e284_c9c3_d5d9b3562d39 --> c2f6615e_96e9_c4eb_5f71_cf120e271705 c3c33304_f44d_798a_9c7b_a80c587ed267["node:https"] f924c5ec_b86a_e284_c9c3_d5d9b3562d39 --> c3c33304_f44d_798a_9c7b_a80c587ed267 155bd823_ceeb_ca16_2d83_f5ec72c22720["node:net"] f924c5ec_b86a_e284_c9c3_d5d9b3562d39 --> 155bd823_ceeb_ca16_2d83_f5ec72c22720 b326953c_dc9d_ec9e_dc34_4beead549f6e["node:os"] f924c5ec_b86a_e284_c9c3_d5d9b3562d39 --> b326953c_dc9d_ec9e_dc34_4beead549f6e f16d8c76_2866_6150_bd14_0347b59abfe9["astro"] f924c5ec_b86a_e284_c9c3_d5d9b3562d39 --> f16d8c76_2866_6150_bd14_0347b59abfe9 style f924c5ec_b86a_e284_c9c3_d5d9b3562d39 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import type http from 'node:http';
import https from 'node:https';
import type { AddressInfo } from 'node:net';
import os from 'node:os';
import type { AstroIntegrationLogger } from 'astro';
const wildcardHosts = new Set(['0.0.0.0', '::', '0000:0000:0000:0000:0000:0000:0000:0000']);
export async function logListeningOn(
logger: AstroIntegrationLogger,
server: http.Server | https.Server,
configuredHost: string | boolean | undefined,
) {
await new Promise<void>((resolve) => server.once('listening', resolve));
const protocol = server instanceof https.Server ? 'https' : 'http';
// Allow to provide host value at runtime
const host = getResolvedHostForHttpServer(configuredHost);
const { port } = server.address() as AddressInfo;
const address = getNetworkAddress(protocol, host, port);
if (host === undefined || wildcardHosts.has(host)) {
logger.info(
`Server listening on \n local: ${address.local[0]} \t\n network: ${address.network[0]}\n`,
);
} else {
logger.info(`Server listening on ${address.local[0]}`);
}
}
function getResolvedHostForHttpServer(host: string | boolean | undefined) {
if (host === false) {
// Use a secure default
return 'localhost';
} else if (host === true) {
// If passed --host in the CLI without arguments
return undefined; // undefined typically means 0.0.0.0 or :: (listen on all IPs)
} else {
return host;
}
}
interface NetworkAddressOpt {
local: string[];
network: string[];
}
// this code from vite https://github.com/vitejs/vite/blob/d09bbd093a4b893e78f0bbff5b17c7cf7821f403/packages/vite/src/node/utils.ts#L892-L914
function getNetworkAddress(
protocol: 'http' | 'https' = 'http',
hostname: string | undefined,
port: number,
base?: string,
) {
const NetworkAddress: NetworkAddressOpt = {
local: [],
network: [],
};
Object.values(os.networkInterfaces())
.flatMap((nInterface) => nInterface ?? [])
.filter((detail) => detail && detail.address && detail.family === 'IPv4')
.forEach((detail) => {
let host = detail.address.replace(
'127.0.0.1',
hostname === undefined || wildcardHosts.has(hostname) ? 'localhost' : hostname,
);
// ipv6 host
if (host.includes(':')) {
host = `[${host}]`;
}
const url = `${protocol}://${host}:${port}${base ? base : ''}`;
if (detail.address.includes('127.0.0.1')) {
NetworkAddress.local.push(url);
} else {
NetworkAddress.network.push(url);
}
});
return NetworkAddress;
}
Domain
Subdomains
Types
Dependencies
- astro
- node:http
- node:https
- node:net
- node:os
Source
Frequently Asked Questions
What does log-listening-on.ts do?
log-listening-on.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RoutingSystem subdomain.
What functions are defined in log-listening-on.ts?
log-listening-on.ts defines 3 function(s): getNetworkAddress, getResolvedHostForHttpServer, logListeningOn.
What does log-listening-on.ts depend on?
log-listening-on.ts imports 5 module(s): astro, node:http, node:https, node:net, node:os.
Where is log-listening-on.ts in the architecture?
log-listening-on.ts is located at packages/integrations/node/src/log-listening-on.ts (domain: CoreAstro, subdomain: RoutingSystem, directory: packages/integrations/node/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free