All blog articles
Engineering · Headless Odoo·Midvex Engineering··8 min read

From Odoo Website to Headless Odoo: Writing Our Own API Module for a Next.js Storefront (Varsco Case Study)

Why we moved Varsco (varsco.com) off Odoo's built-in Website module, how we wrote the custom varsco_content_api Odoo 19 addon, and how we serve an Odoo-backed storefront and B2B portal with Next.js behind a BFF proxy.

Odoo 19Headless CommerceNext.jsCustom API AddonB2B Portal
From Odoo Website to Headless Odoo: Writing Our Own API Module for a Next.js Storefront (Varsco Case Study)

Why Odoo's built-in Website module hit a wall at Varsco

Varsco (VARS Su Ürünleri) runs its entire aquaculture import, distribution, pricing, inventory, CRM, and customs operation inside Odoo 19 Enterprise. In the first phase, keeping the public website inside Odoo's native Website / eCommerce module looked convenient — products and prices were already there.

As commercial requirements grew into a ten-language international storefront and an authenticated B2B portal, three structural limits appeared immediately:

  • Coupled availability & latency: rendering a 10-locale catalog directly from QWeb templates ties marketing TTFB and Core Web Vitals to ERP worker load. Heavy back-office reporting or stock recalculations slow down every public page.
  • Public exposure of the system of record: running the public website on the same Odoo instance forces the ERP onto the public internet, expanding the attack surface around an internal database holding supplier pricing, margins, and customs records.
  • CMS duplication is a trap: syncing products into WordPress, Shopify, or a separate headless CMS creates two sources of truth for stock, tiered B2B pricing, and multi-currency rules — the exact failure mode an ERP exists to eliminate.

The architecture: Odoo stays the source of truth, Next.js owns the glass

Instead of replacing Odoo or duplicating catalog data, we decoupled the presentation layer completely. Odoo 19 stays on a private network as the single system of record, while a modern Next.js frontend serves static/ISR public catalog pages and server-rendered authenticated B2B portal routes.

Crucially, the browser never talks directly to Odoo. Every request flows through a server-side Backend-for-Frontend (BFF) layer. That single constraint eliminates CORS headaches, keeps API bearer tokens strictly on the server, and wraps Odoo sessions in HttpOnly, Secure, SameSite cookies.

Writing our own Odoo API module: varsco_content_api

Exposing raw Odoo XML-RPC or JSON-RPC (`execute_kw`) to a web frontend is brittle and dangerous: model field names leak into UI code, N+1 ORM queries stall page loads, and access rules become hard to audit. Instead, we authored a dedicated Odoo 19 addon — `varsco_content_api` — exposing a versioned `/api/v1` JSON contract.

Each domain gets a clean, typed endpoint with explicit serialization, pagination, and locale resolution:

  • `GET /api/v1/catalog/products` & `/products/<slug>`: returns localized titles, SEO metadata, categories, stock availability flags, and public media URLs in a single pre-joined payload.
  • `POST /api/v1/leads`: accepts validated enquiries with `utm_source`, `utm_medium`, `utm_campaign`, `locale`, and `source_page` mapped directly onto `crm.lead` fields for real CRM attribution.
  • `POST /api/v1/auth/login` & `/portal/*`: proxies Odoo portal authentication and exposes customer-scoped orders, delivery addresses, wishlist, and customs documents (`midvex_customs_op`).
  • `POST /api/v1/checkout`: creates a draft `sale.order` in Odoo and returns a signed payment portal link via `midvex_sale_payment_link`, keeping the Next.js storefront completely outside PCI card scope.
Odoo 19 Controller Pattern (varsco_content_api)python
class CatalogController(http.Controller):
    @http.route("/api/v1/catalog/products", type="http", auth="public", methods=["GET"], csrf=False)
    def list_products(self, lang="en_US", page=1, limit=24, **kw):
        _verify_bearer_token(request.httprequest.headers.get("Authorization"))
        env = request.env(context=dict(request.env.context, lang=lang))
        domain = [("website_published", "=", True), ("sale_ok", "=", True)]
        products = env["product.template"].sudo().search(domain, limit=int(limit), offset=(int(page) - 1) * int(limit))
        payload = [_serialize_product(p) for p in products]
        return _json_response({"items": payload, "page": int(page)})

Serving the Next.js storefront with ISR and BFF caching

On the Next.js side, public catalog and category pages use Server Components with Incremental Static Regeneration (`next: { revalidate: 300, tags: ['catalog'] }`) plus an on-demand `/api/revalidate` webhook triggered from Odoo when a product is published or updated.

That means international visitors hit cached edge HTML in under 50ms while pricing and stock stay anchored to Odoo 19. Authenticated B2B routes opt out of static caching (`cache: 'no-store'`) and forward the user's server-held Odoo session cookie per request.

Next.js Server-Side BFF Fetch (App Router)typescript
export async function fetchOdooCatalog(lang: string, page = 1) {
  const res = await fetch(
    `${process.env.ODOO_INTERNAL_URL}/api/v1/catalog/products?lang=${lang}&page=${page}`,
    {
      headers: { Authorization: `Bearer ${process.env.ODOO_API_TOKEN}` },
      next: { revalidate: 300, tags: ["odoo-catalog"] },
    },
  );
  if (!res.ok) throw new Error(`Odoo API error: ${res.status}`);
  return res.json();
}

What changed in production

Moving Varsco from Odoo Website to headless Odoo with Next.js and `varsco_content_api` separated marketing velocity from ERP stability. Frontend engineers ship UI, structured JSON-LD, and multilingual SEO updates without touching Odoo modules, while the ERP stays isolated behind a private network.

Even better, the `varsco_content_api` addon is now a reusable foundation: launching another Odoo-backed Next.js storefront or B2B portal points a new frontend at the same versioned `/api/v1` contract instead of rebuilding ERP glue code from scratch.

Key engineering takeaways

  • Never expose raw Odoo XML-RPC/JSON-RPC to the browser — define a versioned REST/JSON contract in a dedicated Odoo addon.
  • Keep Odoo off the public internet by routing all browser requests through a Next.js BFF proxy with server-only bearer tokens and HttpOnly cookies.
  • Use ISR + on-demand revalidation webhooks for public catalog speed, and `no-store` per-request SSR for authenticated B2B portal views.
  • Hand checkout off to Odoo's own payment portal links so the frontend stays out of PCI compliance scope.

Want to put a fast Next.js storefront in front of Odoo?

We build custom Odoo API addons, B2B portals, and headless Next.js storefronts without duplicating your ERP data.