Skip to Content
πŸ–₯️ Self-HostingEnvironment Variables

Environment Variables

Sitepins configuration is managed through standard environment variables across two files:

  • api/.env: Express backend server, database, authentication, object storage, and mail settings. Single source of truth is parsed at api/src/config/variables.ts.
  • app/.env: Next.js web application, provider OAuth credentials, WebSocket URLs, and white-label branding tokens.

Values That Must Agree Across Services

A mismatch in any of these variables between api/.env and app/.env will cause session drops, token rejections, or broken preview sandboxes:

Settingapp/.envapi/.envBehavior if mismatched
Internal SecretINTERNAL_API_SECRETINTERNAL_API_SECRETMust be identical. Mismatch produces 401 Unauthorized on preview and verification calls.
API Base URLNEXT_PUBLIC_BACKEND_URLDerived from BASE_URLMust point to the reachable API address.
Cookie DomainUnset (single host)COOKIE_DOMAINIf set on API, must match root domain (e.g. .example.com) across both web and API subdomains.
Bucket URLNEXT_PUBLIC_BUCKET_URLMust match S3_BUCKET_NAME & endpointAvatars/thumbnails upload successfully via API but render as broken 404 images in the UI.

Backend Environment Variables (api/.env)

1. Server Configuration

VariableRequiredDefaultDescription
PORTOptional4000Port on which the Express API listens.
NODE_ENVRequireddevelopmentRuntime environment: development or production.
BASE_URLRequiredhttp://localhost:4000The public URL of the API. Better Auth uses this to construct OAuth callback URLs.
MONGO_URIRequiredβ€”MongoDB connection string (e.g. mongodb://localhost:27017/sitepins).
CORS_ORIGINSRequired (prod)β€”Comma-separated list of browser origins allowed to make credentialed requests (e.g. https://cms.example.com). Ignored in local dev.
TRUST_PROXYOptional1 (prod) / off (dev)Reverse proxy hops. Set to 1 when behind Nginx, Caddy, or Cloudflare; set to false if exposed directly.
JSON_BODY_LIMITOptional5mbMaximum permitted request payload body size.

2. Authentication & Cryptography

VariableRequiredDefaultDescription
BETTER_AUTH_SECRETRequiredβ€”High-entropy session signing key (openssl rand -base64 32). Crashes startup in production if missing.
JWT_SECRETRequiredβ€”Secret key used to sign internal action tokens (openssl rand -hex 32).
JWT_TOKEN_EXPIRERequired7dExpiration window for internal action tokens (e.g. 1d, 7d, 30d).
SANDBOX_ENCRYPTION_KEYRequiredβ€”32-byte hex key (openssl rand -hex 32) used for AES-256-GCM encryption of preview sandbox tokens.
INTERNAL_API_SECRETRequiredβ€”Shared secret string for server-to-server calls (openssl rand -hex 32). Must match app/.env.
SALTOptional10Salt work factor for bcrypt password hashing.
COOKIE_DOMAINOptionalunsetDomain scope for session cookies. Leave unset for single-domain installs. Set to leading-dot (e.g. .example.com) for cross-subdomain setups.
RATELIMIT_WINDOWOptional10Rate-limiting sliding window in seconds.
RATELIMIT_MAXOptional100Maximum requests permitted per IP per rate-limit window.
REQUIRE_EMAIL_VERIFICATIONOptionaltrueSet to false to disable OTP verification at signup for closed intranets or local testing.
DEMO_MODEOptionalfalseWhen true, mounts demo login endpoints for public demonstration instances.

3. OAuth Sign-In (User Login)

These credentials are used strictly for logging in to the Sitepins interface. They are separate from repository access credentials.

VariableRequiredDescription
GITHUB_CLIENT_IDOptionalClient ID from a GitHub OAuth application. Callback: <BASE_URL>/api/v1/auth/callback/github.
GITHUB_CLIENT_SECRETOptionalClient secret from your GitHub OAuth application.
GOOGLE_CLIENT_IDOptionalClient ID from Google Cloud Console. Callback: <BASE_URL>/api/v1/auth/callback/google.
GOOGLE_CLIENT_SECRETOptionalClient secret from Google Cloud Console.

4. S3 Media Storage

Used for application assets (user profile pictures, organization icons, and project cover images). Site content images remain in your Git repository.

VariableRequiredDescription
S3_ENDPOINTRequiredS3 gateway endpoint URL (e.g. https://s3.us-east-1.amazonaws.com or Cloudflare R2 endpoint).
S3_REGIONRequiredStorage region (e.g. us-east-1, or auto for Cloudflare R2).
S3_ACCESS_KEYRequiredS3 access key ID.
S3_SECRET_KEYRequiredS3 secret access key.
S3_BUCKET_NAMERequiredTarget bucket name.
S3_FORCE_PATH_STYLEOptionalSet to true for MinIO or local path-style gateways (http://endpoint/bucket). Default is false.

Existing DigitalOcean Spaces setups using DOS_PUBLIC_ACCESS_KEY, DOS_PUBLIC_SECRET_KEY, DOS_BUCKET_NAME, and DOS_REGION remain fully supported and auto-derive the endpoint.

5. Email & SMTP Configuration

Core uses provider-agnostic transactional email with built-in responsive HTML templates:

VariableDefaultDescription
MAIL_PROVIDERconsole / smtpMail driver. Auto-detected as smtp if SMTP_HOST is present, otherwise defaults to console.
MAIL_FROM_NAMESitepinsSender display name.
MAIL_FROM_EMAILnoreply@example.comβ€œFrom” email address.
SMTP_HOSTβ€”SMTP relay host (e.g. smtp.mailgun.org, email-smtp.us-east-1.amazonaws.com, smtp.resend.com).
SMTP_PORT587SMTP port (typically 587 for TLS or 465 for SSL).
SMTP_SECUREfalseSet to true for port 465 (SSL/TLS direct); false for port 587 (STARTTLS).
SMTP_USERβ€”SMTP authentication username.
SMTP_PASSβ€”SMTP authentication password.
REOON_API_KEYβ€”Optional anti-abuse email validation key at signup. Fails open if omitted or service is unavailable.

Frontend Environment Variables (app/.env)

1. Backend Connectivity & WebSockets

VariableRequiredDescription
NEXT_PUBLIC_BACKEND_URLRequiredPublic URL of the Express API (e.g. http://localhost:4000 or https://api.example.com).
NEXT_PUBLIC_HP_WS_URLRequiredWebSocket URL for collaborative editing (e.g. ws://localhost:4000/api/v1/editor/collab in dev, wss://api.example.com/api/v1/editor/collab in prod).
NEXT_PUBLIC_BUCKET_URLRequiredPublic base URL of your S3 bucket. Also configures the Next.js next/image domain allow-list.
INTERNAL_API_SECRETRequiredMust match INTERNAL_API_SECRET in api/.env identically.
NEXT_PUBLIC_DASHBOARD_HOMEOptionalDefault redirect route after login (default: /dashboard/account).

2. Git Provider Applications (App-Side Only)

These credentials belong strictly to the web app for reading and committing to repositories. The API never holds your private keys.

VariableRequiredDescription
GITHUB_APP_IDRequired for GHNumeric App ID from your GitHub App settings page.
GITHUB_APP_CLIENT_IDRequired for GHClient ID from your GitHub App.
GITHUB_APP_CLIENT_SECRETRequired for GHClient secret generated for your GitHub App.
GITHUB_APP_PRIVATE_KEYRequired for GHFull contents of the downloaded .pem private key, including BEGIN and END headers. Quote with double quotes to preserve newlines.
NEXT_PUBLIC_GITHUB_APP_NAMERequired for GHThe exact name of your GitHub App (used to construct the installation URL).
NEXT_PUBLIC_GITLAB_APP_NAMEOptionalDisplay name for the GitLab integration in the UI.
NEXT_PUBLIC_GITLAB_CLIENT_IDRequired for GLApplication ID from your GitLab OAuth application.
GITLAB_CLIENT_SECRETRequired for GLSecret from your GitLab OAuth application.

3. Artificial Intelligence (BYOK & Server Defaults)

By default, Sitepins is privacy-first: users input their own API keys in their browser (/dashboard/ai-agent), and keys are saved in local storage. You can optionally configure server-wide fallback keys:

VariableDefaultDescription
AI_PROVIDERgroqServer fallback provider: groq, openrouter, openai, gemini, anthropic, or xai.
AI_MODELProvider defaultSpecific model override (e.g. llama-3.3-70b-versatile, gpt-4o-mini, gemini-2.5-flash).
AI_API_KEYβ€”Server-wide API key. Enables AI features for all users without requiring personal keys.

4. White-Label Branding

Sitepins supports complete white-label customization without modifying application source code:

VariableDefaultDescription
NEXT_PUBLIC_BRAND_NAMESitepinsBrand title displayed in headers, titles, and legal footers.
NEXT_PUBLIC_BRAND_URLhttps://sitepins.comHomepage link for the brand.
NEXT_PUBLIC_SUPPORT_URL<BRAND_URL>/contactURL for the β€œSupport” navigation item.
NEXT_PUBLIC_UPDATES_URLhttps://updates.sitepins.comURL for changelog and release updates.
NEXT_PUBLIC_COMMUNITY_URLhttps://discord.gg/KrpvHfqcNACommunity or Discord invitation link.
NEXT_PUBLIC_GIT_COMMIT_EMAIL_DOMAINHost of BRAND_URLEmail domain used for Git commit author attribution (e.g. user@example.com).

5. Demo Mode

VariableDefaultDescription
NEXT_PUBLIC_IS_DEMOfalseEnables a one-click read-only login button on the sign-in screen.
NEXT_PUBLIC_DEMO_EMAILβ€”Pre-populated demo account email address.
NEXT_PUBLIC_DEMO_PASSWORDβ€”Pre-populated demo account password.

When running in Demo Mode, both DEMO_MODE=true in api/.env and NEXT_PUBLIC_IS_DEMO=true in app/.env must be enabled together.

Last updated on