questionnaire docs
Architecture

Multi-Tenant System

How hostname-based tenant resolution works via proxy.js.

Multi-Tenant System

One deployment serves multiple domains (tenants). Each tenant has its own branding, ad configuration, tracking pixels, and content.

Request flow

proxy.js behavior

File: proxy.js (root middleware)

Path patternAction
/_next/*, static filesSkip — no tenant lookup
All other pathsResolve tenant, attach headers

Headers set on the request:

  • x-tenant-id — MongoDB ObjectId of the tenant
  • x-tenant-domain — tenant domain string
  • x-tenant-subdomain — if configured

Localhost development

On localhost or 127.0.0.1, the proxy uses DEV_TENANT_DOMAIN env var (default: getbestanswers.com) instead of the actual hostname.

Tenant document

Key fields on the Tenant model (models/Tenant.js):

FieldPurpose
domainPrimary domain (e.g. getbestanswers.com)
platformNameSite title in header/metadata
adConfigDefault ad units, KV values, provider (adx/adsense)
pixelConfigGoogle/Meta pixel IDs and conversion IDs
taboolaConfigTaboola publisher settings
pushAlertConfigPush notification scripts

Content scoping

All content models (Category, Article, Questionnaire, etc.) are scoped by tenantId with a compound unique index on (tenantId, slug).

Ad config hierarchy

Tenant adConfig provides defaults. Category and Article adConfig override tenant values. See KV Waterfall.

On this page