vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.88k stars 26.86k forks source link

[QUIC protocol] To use middleware you must provide a hostname and port to the Next.js Server #63560

Open Innei opened 7 months ago

Innei commented 7 months ago

Link to the code that reproduces this issue

https://github.com/Innei/next-env-symbol-reproduction

To Reproduce

  1. Next version next@14.1.4
  2. Write a middleware
  3. then call quic:///path

In prod case:

If the cdn enables QUIC protocol, and the cdn is sent back to the server. and the protocol is QUIC

The standalone server will throw an error, and return back a 500 response.

The server error Error: To use middleware you must provide a hostnameandport to the Next.js Server

I found the CDN source URL is quic://0.0.0.0:2323/favicon.ico?__nextDefaultLocale= like this. But here's what the source code says

   if (!url.startsWith("http")) {
            throw new Error("To use middleware you must provide a `hostname` and `port` to the Next.js Server");
        }

So the QUIC protocol is not allowed to access next server

Current vs. Expected behavior

Got error, expected not throw

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Wed Feb 21 21:45:49 PST 2024; root:xnu-10063.101.15~2/RELEASE_ARM64_T6020
Binaries:
  Node: 20.8.1
  npm: 10.2.4
  Yarn: 1.22.21
  pnpm: 8.15.4
Relevant Packages:
  next: 14.1.4
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.4.3
Next.js Config:
  output: standalone

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

Middleware / Edge (API routes, runtime)

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

next start (local), Other (Deployed)

Additional context

No response

SukkaW commented 7 months ago

Isn't HTTP over QUIC just HTTP/3, and it just happens that browsers need HTTP3 to be over TLS?

Innei commented 7 months ago

I don't really know how the Tencent CDN sources back QUIC requests, but the code here on the host server punches in data like this quic://0.0.0.0:2323/favicon.ico?__nextDefaultLocale=