Skip to content

Request URL is incorrect #79182

@VeryCrazyDog

Description

@VeryCrazyDog

Link to the code that reproduces this issue

https://github.com/VeryCrazyDog/nextjs-bug-req-url

To Reproduce

  1. Clone the minimal reproducible repo.
  2. Run npm ci to install dependencies.
  3. Run npm run build to build standalone output.
  4. Run node ./.next/standalone/server.js to run the standalone server. It is expected that the server listening on 0.0.0.0 on network.
    ▲ Next.js 15.4.0-canary.34
    - Local:        http://localhost:3000
    - Network:      http://0.0.0.0:3000
    
  5. Access http://localhost:3000/get/127.0.0.5/show/127.0.0.1 from browser. The request URL printed is incorrect.
    Request URL: http://0.0.0.0:3000/get/localhost/show/127.0.0.1
    
  6. Run npm run dev to run server in development mode.
  7. Access http://server-hostname:3000/get/127.0.0.5/show/127.0.0.1 from browser, where server-hostname is the hostname the running server. The request URL is not showing server-hostname.
    Request URL: http://localhost:3000/get/127.0.0.5/show/127.0.0.1
    

Current vs. Expected behavior

Issue 1: Host name is invalid and pathname being altered

When running server using standalone output and accessing http://localhost:3000/get/127.0.0.5/show/127.0.0.1, the request URL printed is:

http://0.0.0.0:3000/get/localhost/show/127.0.0.1

It is expected the printed request URL is the same as the URL being accessed.

http://localhost:3000/get/127.0.0.5/show/127.0.0.1

Issue 2: Host name is incorrect

When running server using development mode and accessing http://server-hostname:3000/get/127.0.0.5/show/127.0.0.1, where server-hostname is the host name the running server, the request URL printed is:

http://localhost:3000/get/127.0.0.5/show/127.0.0.1

It is expected the printed request URL is the same as the URL being accessed.

http://server-hostname:3000/get/127.0.0.5/show/127.0.0.1

Provide environment information

'yarn' is not recognized as an internal or external command,
operable program or batch file.
'pnpm' is not recognized as an internal or external command,
operable program or batch file.

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 32426
  Available CPU cores: 12
Binaries:
  Node: 20.11.1
  npm: 10.2.4
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.4.0-canary.34 // Latest available version is detected (15.4.0-canary.34).
  eslint-config-next: N/A
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.8.3
Next.js Config:
  output: standalone

Which area(s) are affected? (Select all that apply)

Middleware

Which stage(s) are affected? (Select all that apply)

next dev (local), next start (local), Other (Deployed)

Additional context

For issue pathname being altered, the root cause is because REGEX_LOCALHOST_HOSTNAME is incorrect.

Image
https://regex101.com/r/2KVnEM/1

Metadata

Metadata

Assignees

No one assigned

    Labels

    MiddlewareRelated to Next.js Middleware.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions