make upgrade link environment-aware

This commit is contained in:
Ishaan Gupta 2026-05-29 22:48:38 +05:30
parent 9ed5e871e3
commit 49284cc8f9
2 changed files with 22 additions and 5 deletions

View file

@ -20,6 +20,7 @@ import {
import { Button } from "@ui/components/button"
import { cn } from "@lib/utils"
import { dmSansClassName } from "@/lib/fonts"
import { getBillingSettingsUrl } from "@/lib/url-helpers"
import { GraphIcon, IntegrationsIcon } from "@/components/integration-icons"
import {
DropdownMenu,
@ -81,6 +82,7 @@ export function Header({ onAddMemory, onOpenSearch }: HeaderProps) {
feedbackParam,
)
const { viewMode, setViewMode } = useViewMode()
const billingSettingsUrl = getBillingSettingsUrl()
const handleFeedback = () => setFeedbackOpen(true)
@ -357,7 +359,7 @@ export function Header({ onAddMemory, onOpenSearch }: HeaderProps) {
asChild
className="gap-2.5 rounded-lg px-2.5 py-2 text-sm font-medium text-white/85 hover:bg-white/[0.06] focus:bg-white/[0.06] focus:text-white cursor-pointer"
>
<a href="https://app.supermemory.ai/settings#billing">
<a href={billingSettingsUrl}>
<Zap className="size-4 text-[#4BA0FA]" />
Upgrade
</a>
@ -443,10 +445,7 @@ export function Header({ onAddMemory, onOpenSearch }: HeaderProps) {
dmSansClassName(),
)}
>
<a
href="https://app.supermemory.ai/settings#billing"
aria-label="Upgrade"
>
<a href={billingSettingsUrl} aria-label="Upgrade">
<Zap className="size-3.5 shrink-0 lg:size-4" />
<span className="max-lg:sr-only">Upgrade</span>
</a>

View file

@ -1,4 +1,22 @@
const PROXY_LOCAL_HOSTS = new Set(["localhost", "127.0.0.1", "::1"])
const DEV_APP_ORIGIN = "https://app.dev.supermemory.ai"
const PROD_APP_ORIGIN = "https://app.supermemory.ai"
export function getAppOriginForCurrentEnvironment(hostname?: string): string {
const currentHostname =
hostname ?? (typeof window !== "undefined" ? window.location.hostname : "")
const normalized = currentHostname.toLowerCase()
const isLocalOrDev =
process.env.NODE_ENV !== "production" ||
PROXY_LOCAL_HOSTS.has(normalized) ||
normalized.includes("app.dev.supermemory")
return isLocalOrDev ? DEV_APP_ORIGIN : PROD_APP_ORIGIN
}
export function getBillingSettingsUrl(hostname?: string): string {
return `${getAppOriginForCurrentEnvironment(hostname)}/settings#billing`
}
/** Reconstruct the browser-facing URL when running behind portless (or similar). */
export function getPublicRequestUrl(request: Request): URL {