req.url and req.nextUrl Show Docker Container IP/Port Instead of Real Host #65568
Labels
bug
Issue was opened via the bug report template.
Middleware
Related to Next.js Middleware.
Pages Router
Related to Pages Router.
Runtime
Related to Node.js or Edge Runtime with Next.js.
Link to the code that reproduces this issue
https://github.com/muradsofi/next-13.5.5-req-issue-demo
To Reproduce
Clone the demo repository.
git clone https://github.com/muradsofi/next-13.5.5-req-issue-demo
Build and run the Docker container using the provided Dockerfile.
a) Build the Docker image
docker build -t monorepo-demo -f apps/demo/Dockerfile .
b) Run the Docker container:
docker run -p 3002:3000 monorepo-demo
Access the application in your browser at http://localhost:3002.
Log req.url and req.nextUrl in any API route or middleware.
export default function handler(req, res) { console.log('req.url:', req.url); console.log('req.nextUrl:', req.nextUrl); res.status(200).json({ message: 'Check logs for req.url and req.nextUrl values' }); }
Observe the logs to see that req.url and req.nextUrl display the Docker container's IP address and port. (Observation: Even if you run the app on port 3002, you will get port 3000 in req.url.)
In the deployed environment, the hostname is displayed as localhost with port docker port 3002.
Current vs. Expected behavior
Current Behavior: req.url and req.nextUrl display the Docker container’s IP address and port.
Expected Behavior: req.url and req.nextUrl should display the actual host URL.
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.1.0: Mon Oct 9 21:28:45 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6020 Binaries: Node: 18.17.0 npm: 9.6.7 Yarn: 1.22.22 pnpm: 8.14.3 Relevant Packages: next: 13.5.6 eslint-config-next: 13.4.12 react: 18.2.0 react-dom: 18.2.0 typescript: 5.1.6 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Middleware, Pages Router, Runtime
Which stage(s) are affected? (Select all that apply)
next start (local), Other (Deployed)
Additional context
Deployment Platform: Docker
Issue Started After: Updating to Next.js ^13.5.5
The text was updated successfully, but these errors were encountered: