Skip to content

From Next.js

Terminal window
npx @rep-protocol/codemod --framework next src/
// Before
const apiUrl = process.env.NEXT_PUBLIC_API_URL;
const flags = process.env.NEXT_PUBLIC_FEATURE_FLAGS;
// After
import { rep } from '@rep-protocol/sdk';
const apiUrl = rep.get('API_URL');
const flags = rep.get('FEATURE_FLAGS');

Only NEXT_PUBLIC_* prefixed variables are transformed. Server-side process.env.* access is left unchanged.

Terminal window
npx @rep-protocol/codemod --framework next --dry-run src/
  1. Rename environment variables:

    Terminal window
    NEXT_PUBLIC_API_URL REP_PUBLIC_API_URL
    NEXT_PUBLIC_ANALYTICS_KEY REP_SENSITIVE_ANALYTICS_KEY
  2. Update client-side code:

    import { rep } from '@rep-protocol/sdk';
    const apiUrl = rep.get('API_URL', 'http://localhost:3000');
  3. Install the SDK:

    Terminal window
    npm install @rep-protocol/sdk
  1. Remove NEXT_PUBLIC_* entries from .env.local, .env.production, etc.
  2. Keep server-side process.env.* as-is (these are already server-only)
  3. Run rep typegen for typed access
  4. Update your Dockerfile to include the REP gateway