/ opencodehub / src / lib / site-url.ts
swadhinbiswas feat: OpenCodeHub v1.1.0 - Enterprise Features & Storage Adapters · 2/15/2026
719a1cb
22 lines · 551 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function isProductionRuntime(): boolean {
  return import.meta.env.PROD || process.env.NODE_ENV === "production";
}

function normalizeSiteUrl(url: string): string {
  return url.endsWith("/") ? url.slice(0, -1) : url;
}

export function getSiteUrl(): string {
  const configured = import.meta.env.SITE_URL || process.env.SITE_URL;
  if (configured) {
    return normalizeSiteUrl(configured);
  }

  if (isProductionRuntime()) {
    throw new Error("SITE_URL environment variable is required in production");
  }

  return "http://localhost:4321";
}