Skip to content

Commit 52227ae

Browse files
committed
Normalize backend protocol for web vitals reporting
1 parent 4ee7d67 commit 52227ae

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

frontend/src/app/reportWebVitals.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,27 @@ 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+
function normalizeProtocol(protocol: string | undefined): string | undefined {
7+
if (protocol === undefined) {
8+
return undefined;
9+
}
10+
11+
const trimmedProtocol = protocol.trim();
12+
13+
if (!trimmedProtocol) {
14+
return undefined;
15+
}
16+
17+
return trimmedProtocol.endsWith(':') ? trimmedProtocol : `${trimmedProtocol}:`;
18+
}
19+
620
function buildEndpoint(): string {
721
if (typeof window === 'undefined') {
822
return DEFAULT_ENDPOINT;
923
}
1024

11-
const protocol = process.env.NEXT_PUBLIC_BACKEND_PROTOCOL ?? window.location.protocol ?? 'http:';
25+
const normalizedProtocol = normalizeProtocol(process.env.NEXT_PUBLIC_BACKEND_PROTOCOL);
26+
const protocol = normalizedProtocol ?? window.location.protocol ?? 'http:';
1227
const host = process.env.NEXT_PUBLIC_BACKEND_HOST ?? window.location.hostname;
1328
const port = process.env.NEXT_PUBLIC_BACKEND_PORT ?? '';
1429
const endpoint = process.env.NEXT_PUBLIC_WEB_VITALS_ENDPOINT ?? DEFAULT_ENDPOINT;

0 commit comments

Comments
 (0)