-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(server): hostname defaults to localhost, fix #3355 #3382
Conversation
packages/vite/src/node/utils.ts
Outdated
@@ -464,3 +464,16 @@ export function combineSourcemaps( | |||
export function unique<T>(arr: T[]): T[] { | |||
return Array.from(new Set(arr)) | |||
} | |||
|
|||
export function defaultHostname(host: string | undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (dx, readability): Isn't it more like a normalize or fallback?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is hard to name, it isnt a normalization or fallback either. More like useLocalhostIfPossible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, I trapped and thought it would be the other way around
useLocalhostIfPossible
is ugly, but definitely more expressive about what happens 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya, in #3383 this function is gone so we can discuss how to name other things there :)
Co-authored-by: Nihal Gonsalves <nihal@nihalgonsalves.com>
@@ -129,7 +129,7 @@ export function printServerUrls( | |||
const type = detail.address.includes('127.0.0.1') | |||
? 'Local: ' | |||
: 'Network: ' | |||
const host = detail.address | |||
const host = detail.address.replace('127.0.0.1', 'localhost') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to use defaultHostname
here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to be always 'localhost' when calling it.
hmm, would this still allow to explicitly pass |
I'll close this PR if we merge this alternative #3383 About |
Description
Fix #3355
After #2977, we lost the hostname defaulting to localhost for
'127.0.0.1'
and'0.0.0.0'
vite/packages/vite/src/node/server/index.ts
Line 536 in c374a54
This PR adds that logic back, also including
host === undefined
and'::'
that should be treated equally to '0.0.0.0'The reported URL in the console also replaces
'127.0.0.1'
by localhost now.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).