-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Feat: expose server on local network with new --host flag #2760
Conversation
🦋 Changeset detectedLatest commit: fdf08de The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/astro/src/@types/astro.ts
Outdated
* @type {string} | ||
* @default `'localhost'` | ||
* @default `localhost` | ||
* @deprecated Use --host instead |
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.
how should we handle this in the docgen script?
I think my suggestion would be to ignoring it completely, and add a note in the host
@description
body that it used to be called hostname
.
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.
Made that refactor. Waiting for the docgen updates to merge, but will verify my > blockquote
looks right once those are in 👍
packages/astro/src/cli/index.ts
Outdated
@@ -38,6 +38,7 @@ function printHelp() { | |||
title('Flags'); | |||
table( | |||
[ | |||
['--host [optional host address]', 'Expose server on network'], |
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.
nit: this feels a little verbose for just a summary. What about just '--host [address]'
or '--host [ip]'
? imo advanced details can be left to the documentation.
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.
Fair! Just wanted to clarify that it's optional, so users know --host
could be a boolean flag. Maybe --host [optional IP]
is a good compromise?
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.
☝️ Went ahead with that refactor. Lmk if you like it!
packages/astro/src/core/dev/index.ts
Outdated
const site = config.buildOptions.site ? new URL(config.buildOptions.site) : undefined; | ||
info( | ||
options.logging, | ||
null, | ||
msg.devStart({ startupTime: performance.now() - devStart, port: address.port, localAddress, networkAddress: address.address, site, https: !!viteUserConfig.server?.https }) | ||
msg.devStart({ startupTime: performance.now() - devStart, port: address.port, localAddress, isNetworkExposed, site, https: !!viteUserConfig.server?.https }) |
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.
I thought that --host 1.2.3.4
would work. How does devStart
know to show the correct http://1.2.3.4
URL in the console log if we don't share the host string? Is os.networkInterfaces()
that smart?
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.
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.
cool! TIL
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.
Looking good! Left a few comments
777554f
to
e2aef14
Compare
e2aef14
to
6bea3bb
Compare
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.
Looks good other than a question around passing --host 127.0.0.1
explicitly
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.
LGTM once tests are passing!
import type { AddressInfo } from 'net'; | ||
import type { AstroConfig } from '../@types/astro'; |
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.
Super small nit: we always do import type
at the top of the file.
No need to fix, just FYI.
cce64e8
to
fdf08de
Compare
…2760) * feat: update config to support bool --hostname * fix: show localhost for --hostname=true * feat: address logging feature parity w/ Vite * chore: update type docs * refactor: extract local, network prefs to variable * feat: add --host to --help output * feat: deprecate --hostname, add --host * feat: add --host tests * feat: update preview to support new flags * fix: show --host in dev server log * feat: update config tests for --host flag * chore: test lint * chore: update lock with new fixture * chore: add changeset * refactor: add more details to JSdocs * fix: update path tests * feat: only expose when --host is not local * fix: make flag --help less verbose * fix: address @types comments * fix: lint * chore: remove unused import * fix: use host flag for config test * fix: ensure local logs come before network * refactor: switch up that network logging one last time! * feat: update unit tests * chore: remove debugging block * fix: only parse network logs if network is present
Changes
--host
flag to mirror Vite's config option--host
is absent, the network URL is not exposed on your network--host
is present, the network URL is exposed at a default URL--host [custom host]
is present, the network URL is exposed at [custom host]--hostname [custom host]
is present, the network URL is also exposed at [custom host]--hostname
while maintaining functionalityTesting
preview
command alongsidedev
Docs
Updated configuration and CLI references on docs.
PR here!