Closed Dmitriyx closed 5 months ago
Thanks for the report. This is not a bug, and working as intended.
Hapi can only use the security of its listening endpoint to determine if it should be http:
or https:
. In this case the server has been started as a regular http server.
If you want to know the scheme the client used to connect to the proxy, the proxy will have to signal this to the server, and the server will have to use custom logic to use this signalling to override its understanding of the connecting url. One common way to do this is using the X-Forwarded-Proto
header.
Runtime
node.js
Runtime version
v22
Module version
v21
Last module version without issue
No response
Used with
No response
Any other relevant information
Request.url is part of the URL constructor. https://github.com/hapijs/hapi/blob/master/lib/types/request.d.ts#L470 https://nodejs.org/api/url.html#class-url
What are you trying to achieve or the steps to reproduce?
I am trying to see what url was used to call my api endpoint, using request.url.href is what can be used, however it is incorrect.
Hapi says the http protocol was used instead of https.
Install ngrok, and run cli command
ngrok http 3000
Run Example Server Code:
then execute your cURL command
curl --location '< https ngrok url >'
What was the result you got?
The actual log is:
http://1f0b-47-20-124-200.ngrok-free.app
I got the url with the http protocol instead of https.What result did you expect?
What I expected to get:
https://1f0b-47-20-124-200.ngrok-free.app
I also checked the URL class.
this logs the correctly
an example using vanilla server to construct full url.