Skip to content

Commit

Permalink
Log the TLS certificate hostname instead of localhost during develo…
Browse files Browse the repository at this point in the history
…pment server startup when the HTTPS protocol is being used (#105)
  • Loading branch information
mangs authored Oct 3, 2024
1 parent ea6a26e commit 6d26b73
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.33.0

- Log the TLS certificate hostname instead of `localhost` during development server startup when the HTTPS protocol is being used

## 2.32.1

- Fix development server bug wherein `onLogRequestBody` would never be called
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mangs/bun-utils",
"version": "2.32.1",
"version": "2.33.0",
"author": "Eric L. Goldstein",
"description": "Useful utils for your Bun projects",
"engines": {
Expand Down
17 changes: 10 additions & 7 deletions src/networkUtils.mts
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,21 @@ function getColorByStatusCode(statusCode: number) {

/**
* Log the development server's startup sequence to the console.
* @param server The return value of `Bun.serve()`.
* @param server.url The URL API object representing the running server instance.
* @param server.url.href The full URL string representing the running server instance.
* @param serverHref The full URL string representing the running server instance.
* @param tlsServerName The TLS certificate hostname to expect when connecting to the server.
*/
function logServerStartup({ url: { href } }: Server) {
function logServerStartup(
serverHref: Server['url']['href'],
tlsServerName: HttpsOptions['serverName'],
) {
globalThis.hotReloadCount ??= 0;
const { hotReloadCount } = globalThis;

const listenUrl = tlsServerName ? `https://${tlsServerName}/` : serverHref;
const hotCountString = hotReloadCount > 0 ? ` (hot reload count: ${hotReloadCount})` : '';
const formatString = 'Development server listening on %s%s';
const heading = format(formatString, href, hotCountString);
const headingColor = format(formatString, href, dim(hotCountString));
const heading = format(formatString, listenUrl, hotCountString);
const headingColor = format(formatString, listenUrl, dim(hotCountString));
const separator = dim('='.repeat(stringWidth(heading)));
console.log(headingColor);
console.log(separator);
Expand Down Expand Up @@ -319,7 +322,7 @@ async function startDevelopmentServer(
}

const developmentServer = serve(serverOptions);
logServerStartup(developmentServer);
logServerStartup(developmentServer.url.href, httpsOptions?.serverName);
return developmentServer;
}

Expand Down

0 comments on commit 6d26b73

Please sign in to comment.