Skip to content

x-forwarded-port header is 'undefined' when no port in url  #61133

@yuvalotem

Description

@yuvalotem

Link to the code that reproduces this issue

https://github.com/yuvalotem1/x-forwarded-port-header--undefined-

To Reproduce

  1. Create new next application
  2. Inside pages/api/[...middleware].ts add this function -
    export default function apiMiddleware(req: NextApiRequest) {
    //this will log 'undefined'
    console.log('x-forwarded-port ', req.headers['x-forwarded-port ']);
    }
  3. deploy to vercel
  4. check the logs and see x-forwarded-port log

Current vs. Expected behavior

Expected behavior to not have the header/to have 80/443 as the default value
using http-proxy with api-router crashes because invalid x-forwarded-port header value 'undefined'

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000
Binaries:
  Node: 18.18.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 14.1.1-canary.10 // Latest available version is detected (14.1.1-canary.10).
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: N/A

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

Middleware / Edge (API routes, runtime)

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

Vercel (Deployed)

Additional context

No response

NEXT-2778

Metadata

Metadata

Labels

RuntimeRelated to Node.js or Edge Runtime with Next.js.bugIssue was opened via the bug report template.linear: nextConfirmed issue that is tracked by the Next.js team.locked

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions