Implement Next.js + NGINX Runtime Configuration POC #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements the specification defined in
specs/nextjs-nginx.md
, creating a complete proof-of-concept for deploying Next.js applications with NGINX and runtime configuration injection.Overview
The implementation demonstrates how to deploy a Next.js application where configuration can be changed at runtime without rebuilding the application. This is achieved through NGINX's
sub_filter
directive to inject configuration values into the HTML at serve time.Key Features
Architecture
The system works by:
<script id="runtime-config">window.__RUNTIME_CONFIG__ = {};</script>
sub_filter
to replace the placeholder with actual configuration values from environment variablesImplementation Details
Configuration System
Created a centralized configuration utility (
lib/config.ts
) that:window.__RUNTIME_CONFIG__
on the clientDemo Application
Built a comprehensive demo application showcasing:
NGINX Integration
Testing
Includes comprehensive testing:
Example test output:
Benefits
Files Added
sites/demo-app/
: Complete Next.js application with configuration demoDockerfile
: Multi-stage build for production deploymentnginx.conf.template
: NGINX configuration with runtime injectiondocker-compose.yml
: Easy local testing setuptest-runtime-config.sh
: Automated testing scriptREADME.md
: Comprehensive documentation and usage guideThis implementation successfully demonstrates that modern Next.js applications can be deployed with runtime configuration flexibility while maintaining optimal performance and developer experience.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
fonts.googleapis.com
/usr/local/bin/node /home/REDACTED/work/data-fetching-monorepo-poc/data-fetching-monorepo-poc/sites/demo-app/node_modules/.pnpm/next@15.5.0_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/next/dist/compiled/jest-worker/processChild.js
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.