Middleware forcing HTTPS even though NextResponse rewrite specifies HTTP (X-Middleware-Rewrite:)
Unanswered
McKay's Bunting posted this in #help-forum
McKay's BuntingOP
I have the following middleware. It works locally, but when my server is running with HTTPS, it for some reason tries to do the rewrite to
https://localhost:8000, not http://localhost:8000. Why is that? I clearly specify the protocol as http://. My backend server and my front-end are running on the same VPC and node, so I just want to communicate over HTTP locally, but the middleware keeps injecting HTTPS. Is this a bug? export function middleware(request: NextRequest) {
const requestHeaders = new Headers(request.headers);
const updatedUrl = request.nextUrl.clone();
updatedUrl.host = "localhost:8000";
updatedUrl.protocol = "http:";
const response = NextResponse.rewrite(updatedUrl.toString(), {
request: {
headers: requestHeaders,
},
});
return response;
}2 Replies
McKay's BuntingOP
My middleware rewrite has
https in it.Netherland Dwarf
What service are you running your app on?