All files / apps/web/src/utils url.ts

100% Statements 3/3
100% Branches 0/0
100% Functions 1/1
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 262x 3x 3x                                              
export const getHostUrl = (url: string) => {
	const urlObject = new URL(url);
	return `${urlObject.protocol}//${urlObject.host}/`;
};
 
/* c8 ignore start */
/* oxlint-disable node/no-process-env */
// see https://github.com/openchamber/openchamber/issues/4312
export const getServerHostUrl = (url: string) => {
	const parsed = new URL(url);
	const isOpenCode =
		import.meta.env.MODE !== "test" && Boolean(process.env.OPENCODE);
	const port = process.env.PORT;
	if (
		isOpenCode &&
		port &&
		parsed.port !== port &&
		["localhost", "127.0.0.1", "[::1]"].includes(parsed.hostname)
	) {
		parsed.port = port;
	}
	return getHostUrl(parsed.toString());
};
/* oxlint-enable node/no-process-env */
/* c8 ignore stop */