-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
Closed
Labels
urlIssues and PRs related to the legacy built-in url module.Issues and PRs related to the legacy built-in url module.
Description
I have been using the code below:
request.post(url.format({
protocol: 'http',
host: 'localhost',
port: port,
pathname: '/my-route'
}), {
body: { value: 'foobar' },
json: true
}, function (err, res, body) {
if (err) {
return console.error(err);
}
console.log('Sent data.');
});
All I get is an EPIPE
error. Finally, after two hours (!), I figured out what the problem was: It should be
url.format({
protocol: 'http',
hostname: 'localhost',
port: port,
pathname: '/my-route'
})
and not:
url.format({
protocol: 'http',
host: 'localhost',
port: port,
pathname: '/my-route'
})
So it's host
vs hostname
, and about ignoring the port when host
is given. This error is quite annoying for several reasons:
- In fairly complex applications, you first look for the error everywhere else (where more logic is involved).
host
vshostname
is too easy to mix up.- There is no error message telling you that it doesn't make sense to provide a port if you use
host
instead ofhostname
.
So, to cut a long story short: Would verifying this be helpful?
What I'm thinking of is just a small test that checks whether you provide host
and port
. If so, it should tell you that port
is ignored and you should either remove it, or use hostname
instead.
What do you think?
Metadata
Metadata
Assignees
Labels
urlIssues and PRs related to the legacy built-in url module.Issues and PRs related to the legacy built-in url module.