import { PUBLIC_API_URL } from "../config/environment";

/**
 * When PUBLIC_API_URL is set (e.g. https://api.example.com — no path, no trailing slash),
 * redirects use that origin so OAuth callbacks land on canonical TLS (typically :443 / reverse proxy)
 * instead of staying on a raw Node port.
 */
export function absoluteOrRelativeRedirect(pathWithQuery: string): string {
  const p = pathWithQuery.startsWith("/") ? pathWithQuery : `/${pathWithQuery}`;
  if (PUBLIC_API_URL) {
    return `${PUBLIC_API_URL}${p}`;
  }
  return p;
}
