fix(docker): use next-runtime instead of accessing next_public vars directly#746
fix(docker): use next-runtime instead of accessing next_public vars directly#746waleedlatif1 merged 1 commit intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
|
✅ No security or compliance issues detected. Reviewed everything up to 8ea6a22. Security Overview
Detected Code Changes
Reply to this PR with |
There was a problem hiding this comment.
Greptile Summary
This PR introduces Docker runtime environment variable support by integrating the next-runtime-env library into the application's environment configuration system. The core change is the addition of a getEnv() utility function in lib/env.ts that prioritizes runtime environment variable injection over static process.env access for client-side NEXT_PUBLIC_ variables.
The implementation adds a fallback mechanism where getEnv() first attempts to retrieve variables from next-runtime-env (for Docker runtime injection) and falls back to process.env if the runtime library is unavailable. This approach specifically targets the Docker deployment issue where Next.js embeds NEXT_PUBLIC_ variables at build time, making it impossible to configure socket URLs and other dynamic settings without rebuilding container images.
The change selectively applies this new approach to client-side variables like NEXT_PUBLIC_SOCKET_URL, NEXT_PUBLIC_APP_URL, and authentication-related Google configuration variables, while preserving process.env access for server-only variables (VERCEL_URL) and build-time constants (NODE_ENV). This selective application demonstrates understanding of which environment variables need runtime flexibility versus which should remain static.
The integration fits well with the existing environment management system built on @t3-oss/env-nextjs and maintains the same validation and type safety patterns already established in the codebase. The getEnv() function is exported for potential use in other modules that need similar runtime variable access.
Confidence score: 4/5
- This is a solid technical solution that addresses a real Docker deployment problem with minimal risk.
- The implementation is clean, follows existing patterns, and maintains backward compatibility with proper fallback handling.
- The selective application of
getEnv()shows good judgment about which variables need runtime flexibility, though the missing package.json update needs attention.
1 file reviewed, no comments
Description
Added next-runtime-env to enable Docker runtime environment variable injection for NEXT_PUBLIC_ vars. Fixes Docker deployments where socket URLs were hardcoded at build time.
Fixes # (issue)
Type of change
How Has This Been Tested?
Tested runtime variable injection with custom NEXT_PUBLIC_SOCKET_URL values in development environment. Verified getEnv() function returns runtime values when available and falls back to process.env.
Checklist:
bun run test)Security Considerations: