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

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

Merged
merged 1 commit into from
Oct 3, 2024
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
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