fix(middleware): strip port 3000 from reconstructed URL to prevent hydration mismatch
All checks were successful
Build & Deploy KLZ Cables / 🔍 Prepare Environment (push) Successful in 7s
Build & Deploy KLZ Cables / 🧪 Quality Assurance (push) Successful in 1m30s
Build & Deploy KLZ Cables / 🏗️ Build Gatekeeper (push) Successful in 21s
Build & Deploy KLZ Cables / 🏗️ Build App (push) Successful in 4m38s
Build & Deploy KLZ Cables / 🚀 Deploy (push) Successful in 50s
Build & Deploy KLZ Cables / ⚡ PageSpeed (push) Successful in 7m12s
Build & Deploy KLZ Cables / 🔔 Notifications (push) Successful in 2s
All checks were successful
Build & Deploy KLZ Cables / 🔍 Prepare Environment (push) Successful in 7s
Build & Deploy KLZ Cables / 🧪 Quality Assurance (push) Successful in 1m30s
Build & Deploy KLZ Cables / 🏗️ Build Gatekeeper (push) Successful in 21s
Build & Deploy KLZ Cables / 🏗️ Build App (push) Successful in 4m38s
Build & Deploy KLZ Cables / 🚀 Deploy (push) Successful in 50s
Build & Deploy KLZ Cables / ⚡ PageSpeed (push) Successful in 7m12s
Build & Deploy KLZ Cables / 🔔 Notifications (push) Successful in 2s
This commit is contained in:
@@ -24,17 +24,20 @@ export default function middleware(request: NextRequest) {
|
||||
let effectiveRequest = request;
|
||||
if (url.includes('0.0.0.0')) {
|
||||
const proto = headers.get('x-forwarded-proto') || 'https';
|
||||
const host = headers.get('host') || 'testing.klz-cables.com';
|
||||
const host = headers.get('x-forwarded-host') || headers.get('host') || 'testing.klz-cables.com';
|
||||
const newUrl = new URL(url);
|
||||
newUrl.protocol = proto;
|
||||
newUrl.host = host;
|
||||
// Split host to remove port if present
|
||||
const [hostname] = host.split(':');
|
||||
newUrl.hostname = hostname;
|
||||
newUrl.port = ''; // Explicitly clear the port to avoid leaking :3000
|
||||
effectiveRequest = new NextRequest(newUrl, {
|
||||
headers: request.headers,
|
||||
method: request.method,
|
||||
body: request.body,
|
||||
});
|
||||
console.log(
|
||||
`Replaced 0.0.0.0 URL with: ${newUrl.toString()} | Original Host: ${headers.get('host')} | Headers: ${JSON.stringify(headerObj)}`,
|
||||
`Replaced 0.0.0.0 URL with: ${newUrl.toString()} | Original Host: ${headers.get('host')} | Forwarded Host: ${headers.get('x-forwarded-host')}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user