Point production login/checkout at customer.sanihome.ir.
Stop baking the local Vite URL into storefront builds when CUSTOMER_ORIGIN is unset. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
f0d8276c3e
commit
10c70359aa
@@ -0,0 +1,6 @@
|
||||
# Used by `next build` on the websites VM (production).
|
||||
# Local `next dev` still prefers `.env.local`.
|
||||
NEXT_PUBLIC_API_BASE_URL=https://api.meshkee.com/api/v1
|
||||
NEXT_PUBLIC_DOMAIN=sanihome.ir
|
||||
NEXT_PUBLIC_CUSTOMER_ORIGIN=https://customer.sanihome.ir
|
||||
NEXT_PUBLIC_BUSINESS_ORIGIN=https://business.sanihome.ir
|
||||
@@ -4,27 +4,42 @@ import { DOMAIN } from "@/lib/meshkee";
|
||||
|
||||
/**
|
||||
* Shared checkout lives on the customer dashboard (all websites).
|
||||
* Local: http://customer.sanihome.com:5175
|
||||
* Prod: https://customer.sanihome.com
|
||||
* Local: http://customer.{domain}:5175
|
||||
* Prod: https://customer.{domain}
|
||||
*
|
||||
* Prefer NEXT_PUBLIC_CUSTOMER_ORIGIN. Otherwise derive from DOMAIN + build mode
|
||||
* so production deploys never bake in the local Vite URL.
|
||||
*/
|
||||
export const CUSTOMER_ORIGIN =
|
||||
process.env.NEXT_PUBLIC_CUSTOMER_ORIGIN?.replace(/\/$/, "") ||
|
||||
"http://customer.sanihome.com:5175";
|
||||
function resolveCustomerOrigin(): string {
|
||||
const configured = process.env.NEXT_PUBLIC_CUSTOMER_ORIGIN?.replace(/\/$/, "");
|
||||
if (configured) return configured;
|
||||
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
return `https://customer.${DOMAIN}`;
|
||||
}
|
||||
|
||||
return `http://customer.${DOMAIN}:5175`;
|
||||
}
|
||||
|
||||
export const CUSTOMER_ORIGIN = resolveCustomerOrigin();
|
||||
|
||||
/**
|
||||
* Business dashboard for website admins.
|
||||
* Local: http://business.sanihome.com:5173
|
||||
* Local: http://business.{domain}:5173
|
||||
* Prod: https://business.{domain}
|
||||
*/
|
||||
export function businessDashboardUrl(): string {
|
||||
const configured = process.env.NEXT_PUBLIC_BUSINESS_ORIGIN?.replace(/\/$/, "");
|
||||
if (configured) return `${configured}/`;
|
||||
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
return `https://business.${DOMAIN}/`;
|
||||
}
|
||||
|
||||
if (typeof window !== "undefined") {
|
||||
const { protocol, port } = window.location;
|
||||
if (port === "3000" || port === "3001" || port === "") {
|
||||
const portSuffix = port === "3000" || port === "3001" ? ":5173" : "";
|
||||
return `${protocol}//business.${DOMAIN}${portSuffix}/`;
|
||||
if (port === "3000" || port === "3001") {
|
||||
return `${protocol}//business.${DOMAIN}:5173/`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user