Skip to content

Commit 944895a

Browse files
📝 Add docstrings to codex/add-web-vitals-reporting-to-backend
Docstrings generation was requested by @shayancoin. * #144 (comment) The following files were modified: * `frontend/src/app/reportWebVitals.ts`
1 parent 52227ae commit 944895a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

frontend/src/app/reportWebVitals.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import type { Metric } from 'next/app';
33
const DEFAULT_ENDPOINT = '/observability/web-vitals';
44
const APP_LABEL = process.env.NEXT_PUBLIC_WEB_VITALS_APP ?? 'frontend';
55

6+
/**
7+
* Normalize a protocol string to ensure a trailing colon or return `undefined` for empty/undefined input.
8+
*
9+
* @param protocol - The protocol string to normalize (e.g., "http", "https:", or undefined). Leading/trailing whitespace is ignored.
10+
* @returns The normalized protocol with a trailing colon (e.g., "https:") or `undefined` if `protocol` is `undefined` or empty after trimming.
11+
*/
612
function normalizeProtocol(protocol: string | undefined): string | undefined {
713
if (protocol === undefined) {
814
return undefined;
@@ -17,6 +23,11 @@ function normalizeProtocol(protocol: string | undefined): string | undefined {
1723
return trimmedProtocol.endsWith(':') ? trimmedProtocol : `${trimmedProtocol}:`;
1824
}
1925

26+
/**
27+
* Build the full URL used to report web-vitals metrics.
28+
*
29+
* @returns The endpoint URL constructed from environment overrides (protocol, host, port, endpoint) with browser location fallbacks; returns `DEFAULT_ENDPOINT` when not running in a browser.
30+
*/
2031
function buildEndpoint(): string {
2132
if (typeof window === 'undefined') {
2233
return DEFAULT_ENDPOINT;
@@ -67,4 +78,4 @@ export function reportWebVitals(metric: Metric) {
6778
});
6879

6980
sendMetric(endpoint, body);
70-
}
81+
}

0 commit comments

Comments
 (0)