xcladeDocs

Headless Starter Storefront

Build and deploy a custom Next.js storefront wired to xclade Go GraphQL and @xclade/sdk v2

Headless Starter Storefront

If you prefer hosting a bespoke Next.js storefront outside of Storefront Studio, you can clone the xclade Store Starter or wire @xclade/sdk directly into any React, Next.js, Remix, or mobile app.


Prerequisites

  • Node.js 20+ and pnpm
  • An xclade store provisioned in xclade Console
  • A Publishable API Key (pk_...) linked to your Storefront Sales Channel

Setup

1. Clone & Install

git clone https://github.com/xclade/businessx.git
cd businessx
pnpm install

2. Configure Environment Variables

Copy .env.example to .env.local and point it at your isolated store pod:

# Your store's Go backend origin (Storefront GraphQL is served at /graphql)
NEXT_PUBLIC_XCLADE_API_URL=https://{shortId}.api.myxclade.com

# Publishable API Key scoping catalog, pricing & carts to your Sales Channel
NEXT_PUBLIC_XCLADE_PUBLISHABLE_KEY=pk_live_...

Generate a Publishable API Key inside your store's Admin Console (https://{shortId}.api.myxclade.com/app) under Settings → Publishable API Keys, and add your local/production storefront origin under Settings → Store Configuration so dynamic CORS permits browser requests to /graphql.

3. Run Locally

pnpm dev

Connecting with @xclade/sdk v2

In any custom Next.js App Router project:

// lib/xclade.ts
import { createXcladeSDK } from '@xclade/sdk';

export const xclade = createXcladeSDK({
  baseUrl: process.env.NEXT_PUBLIC_XCLADE_API_URL!,
  publishableKey: process.env.NEXT_PUBLIC_XCLADE_PUBLISHABLE_KEY!,
});
// app/products/page.tsx
import { xclade } from '@/lib/xclade';

export default async function ProductsPage() {
  const { products } = await xclade.store.listProducts({
    limit: 24,
    currency_code: 'usd',
  });

  return (
    <ul>
      {products.map((p: any) => (
        <li key={p.id}>{p.title}</li>
      ))}
    </ul>
  );
}

Deploying to Production

  1. Add your production storefront origin (e.g. https://shop.yourbrand.com) to your store's allowed origins in Settings → Store Configuration (or connect it as a custom domain in the xclade Console).
  2. Set NEXT_PUBLIC_XCLADE_API_URL and NEXT_PUBLIC_XCLADE_PUBLISHABLE_KEY in Vercel or your hosting provider.
  3. Deploy and verify POST /graphql returns X-Cache: HIT on repeat anonymous catalog queries.

Next Steps

On this page