Skip to content

Conversation

@tomelliot
Copy link

@tomelliot tomelliot commented Oct 6, 2025

Cloudflare/Nuxt aren't successfully combining the runtimeConfig as expected. This fixes it.

Resolves this issue: #190

Summary by CodeRabbit

  • Chores
    • Configuration now supports providing the site token via environment variables. If not set, a unique token is generated automatically at startup. This improves deployment flexibility and consistency across environments. No user-facing changes or UI impact. Recommended for managed/hosted deployments.

@coderabbitai
Copy link

coderabbitai bot commented Oct 6, 2025

Walkthrough

The configuration initializes runtime siteToken from the NUXT_SITE_TOKEN environment variable when available, otherwise falls back to crypto.randomUUID().

Changes

Cohort / File(s) Summary
Config Initialization
nuxt.config.ts
Updated runtime config to read siteToken from process.env.NUXT_SITE_TOKEN with fallback to crypto.randomUUID(), altering initialization precedence.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Env as Process Env (NUXT_SITE_TOKEN)
  participant Nuxt as Nuxt Config Init
  participant Runtime as RuntimeConfig

  Env-->>Nuxt: Provide NUXT_SITE_TOKEN?
  alt Env var present
    Nuxt->>Runtime: siteToken = NUXT_SITE_TOKEN
  else Env var absent
    Nuxt->>Nuxt: generate crypto.randomUUID()
    Nuxt->>Runtime: siteToken = generated UUID
  end

  note over Runtime: siteToken available for app usage
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my whiskers at a token’s fate,
From env it hops, or UUID we create.
Config burrow neat, decisions clear,
A secret string, now far or near.
Thump-thump—deploy! with gentle cheer. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately and concisely describes the primary change of reading the site token from an environment variable with a fallback to a generated UUID, which aligns with the implementation details of the pull request.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cf21a2d and 5614ab2.

📒 Files selected for processing (1)
  • nuxt.config.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,vue}

📄 CodeRabbit inference engine (AGENT.md)

**/*.{ts,tsx,vue}: Use TypeScript for all new code
Use camelCase for variables and functions

Files:

  • nuxt.config.ts
🔇 Additional comments (1)
nuxt.config.ts (1)

23-23: Verify that NUXT_SITE_TOKEN is required for production environments.

The change correctly addresses the runtimeConfig issue by prioritizing the environment variable. However, the crypto.randomUUID() fallback will generate a new token on each server restart when NUXT_SITE_TOKEN is not set, which could disrupt functionality if the token is used for authentication or persistent sessions.

Ensure that:

  1. NUXT_SITE_TOKEN is documented as required for production deployments
  2. Deployment guides or setup documentation specify setting this environment variable

Consider adding runtime validation to warn developers when NUXT_SITE_TOKEN is not set in production:

siteToken: (() => {
  const token = process.env.NUXT_SITE_TOKEN || crypto.randomUUID()
  if (!process.env.NUXT_SITE_TOKEN && process.env.NODE_ENV === 'production') {
    console.warn('⚠️ NUXT_SITE_TOKEN not set in production - using generated UUID. This will change on each restart!')
  }
  return token
})(),

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant