logoPay4SaaS
Deploy

Dual-Domain Setup

Pay4SaaS supports running two independent sites from one codebase — for example, an international site (example.com) and a domestic China site (example.cn). Everything is controlled via environment variables with zero code changes.

How It Works

Each domain is a separate deployment with its own .env file. The key environment variable is NEXT_PUBLIC_LOCALE_SITE:

  • Primary site (e.g. .com): NEXT_PUBLIC_LOCALE_SITE is not set
  • Secondary site (e.g. .cn): NEXT_PUBLIC_LOCALE_SITE=cn
# Primary site (.com) — no NEXT_PUBLIC_LOCALE_SITE
NEXT_PUBLIC_SITE_URL=https://www.example.com
NEXT_PUBLIC_PAYMENT_PROVIDERS=stripe,paypal

# Secondary site (.cn) — set NEXT_PUBLIC_LOCALE_SITE
NEXT_PUBLIC_LOCALE_SITE=cn
NEXT_PUBLIC_SITE_URL=https://www.example.cn
NEXT_PUBLIC_PAYMENT_PROVIDERS=alipay

What Changes

Triggered by NEXT_PUBLIC_LOCALE_SITE=cn (value is cn)

AreaPrimary SiteSecondary Site (cn)
CurrencyUSD ($)CNY (¥)
Pricesamount / priceamountCNY / priceCNY
Default languageEnglishChinese
Terms / PrivacyEnglish versionChinese version
ICP filing badgeHiddenShown (if NEXT_PUBLIC_ICP_BEIAN is set)
Trial periodEnabledDisabled

Triggered by NEXT_PUBLIC_LOCALE_SITE existing (any value)

As long as this variable is set — regardless of what the value is — the site is treated as a secondary site, and SEO is fully disabled:

AreaPrimary SiteSecondary Site
robots.txtAllow: /Disallow: /
SitemapFull sitemapEmpty
Meta robotsNot setnoindex, nofollow

This means only your primary domain gets indexed by search engines.

Environment Variables That Differ

VariablePrimary (.com)Secondary (.cn)Purpose
NEXT_PUBLIC_LOCALE_SITE(not set)cnEnable secondary site mode
NEXT_PUBLIC_SITE_URLhttps://www.example.comhttps://www.example.cnBase URL for links, sitemap, OG tags
NEXT_PUBLIC_PAYMENT_PROVIDERSstripe,paypal,creemalipayWhich payment buttons to show
NEXT_PUBLIC_PRICING_MODELYour choiceYour choiceCan be different per domain
NEXT_PUBLIC_ICP_BEIAN(not set)Filing numberChina ICP filing badge
NEXT_PUBLIC_CONTACT_EMAILInternational emailDomestic emailShown on contact pages

Payment provider secrets (Stripe keys, Alipay keys, etc.) should only be set on the deployment that uses them.

Local Development

Use npm run dev:cn to preview the secondary site locally. This loads .env.local.cn which sets NEXT_PUBLIC_LOCALE_SITE=cn.

npm run dev       # Preview as primary site
npm run dev:cn    # Preview as secondary site

Pricing Configuration

In config/payment.ts, each plan supports dual pricing:

basic: {
  amount: 9.99,          // USD — used on primary site
  amountCNY: 29,         // CNY — used on secondary site (cn)
  // ...
}

If amountCNY is not set, the secondary site falls back to the USD price.

Shared Database

Both deployments can share the same Supabase database. User accounts, subscriptions, and usage data are shared across domains. Cookie domain is automatically extracted from NEXT_PUBLIC_SITE_URL to ensure proper session handling.

Deployment

Each domain needs its own deployment (e.g. two Vercel projects, or one Vercel + one VPS). The only difference is the environment variables — the code is identical.

  1. Deploy the primary site with your primary .env
  2. Deploy the secondary site with NEXT_PUBLIC_LOCALE_SITE=cn and secondary-specific env vars
  3. Both deployments point to the same Git repo and same branch

On this page