Skip to content
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

Merged
merged 27 commits into from
Mar 11, 2022
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
08898e4
feat: update config to support bool --hostname
bholmesdev Mar 10, 2022
c004d55
fix: show localhost for --hostname=true
bholmesdev Mar 10, 2022
4df8154
feat: address logging feature parity w/ Vite
bholmesdev Mar 10, 2022
3579ebe
chore: update type docs
bholmesdev Mar 10, 2022
0b507be
refactor: extract local, network prefs to variable
bholmesdev Mar 10, 2022
06ddb45
feat: add --host to --help output
bholmesdev Mar 10, 2022
76c4bcc
feat: deprecate --hostname, add --host
bholmesdev Mar 10, 2022
2e165f9
feat: add --host tests
bholmesdev Mar 10, 2022
5f2ae80
feat: update preview to support new flags
bholmesdev Mar 10, 2022
d153b59
fix: show --host in dev server log
bholmesdev Mar 10, 2022
dd14845
feat: update config tests for --host flag
bholmesdev Mar 10, 2022
e005346
chore: test lint
bholmesdev Mar 10, 2022
d2fbaa1
chore: update lock with new fixture
bholmesdev Mar 10, 2022
f5f7c2d
chore: add changeset
bholmesdev Mar 10, 2022
86ac493
refactor: add more details to JSdocs
bholmesdev Mar 10, 2022
4004d6b
fix: update path tests
bholmesdev Mar 10, 2022
6c2554d
feat: only expose when --host is not local
bholmesdev Mar 11, 2022
df5d70c
fix: make flag --help less verbose
bholmesdev Mar 11, 2022
30c125c
fix: address @types comments
bholmesdev Mar 11, 2022
b1c50d6
fix: lint
bholmesdev Mar 11, 2022
32ad433
chore: remove unused import
bholmesdev Mar 11, 2022
e966d3d
fix: use host flag for config test
bholmesdev Mar 11, 2022
6bea3bb
fix: ensure local logs come before network
bholmesdev Mar 11, 2022
0ff49d6
refactor: switch up that network logging one last time!
bholmesdev Mar 11, 2022
d21e981
feat: update unit tests
bholmesdev Mar 11, 2022
4ed56cd
chore: remove debugging block
bholmesdev Mar 11, 2022
fdf08de
fix: only parse network logs if network is present
bholmesdev Mar 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: extract local, network prefs to variable
  • Loading branch information
bholmesdev committed Mar 11, 2022
commit 0b507be3901fe80a65aad6105b6fae91cc346d1c
8 changes: 5 additions & 3 deletions packages/astro/src/core/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,23 @@ export function devStart({
// PACKAGE_VERSION is injected at build-time
const version = process.env.PACKAGE_VERSION ?? '0.0.0';
const rootPath = site ? site.pathname : '/';
const localPrefix = `${dim('┃')} Local `;
const networkPrefix = `${dim('┃')} Network `;
const toDisplayUrl = (hostname: string) => `${https ? 'https' : 'http'}:https://${hostname}:${port}${rootPath}`;
let addresses = [];

if (!isNetworkExposed) {
addresses = [`${dim('┃')} Local ${bold(cyan(toDisplayUrl(localAddress)))}`, `${dim('┃')} Network ${dim('use --hostname to expose')}`];
addresses = [`${localPrefix}${bold(cyan(toDisplayUrl(localAddress)))}`, `${networkPrefix}${dim('use --hostname to expose')}`];
} else {
addresses = Object.values(os.networkInterfaces())
.flatMap((networkInterface) => networkInterface ?? [])
.filter((networkInterface) => networkInterface?.address && networkInterface?.family === 'IPv4')
.map(({ address }) => {
if (address.includes('127.0.0.1')) {
const displayAddress = address.replace('127.0.0.1', localAddress);
return `${dim('┃')} Local ${bold(cyan(toDisplayUrl(displayAddress)))}`;
return `${localPrefix}${bold(cyan(toDisplayUrl(displayAddress)))}`;
} else {
return `${dim('┃')} Network ${bold(cyan(toDisplayUrl(address)))}`;
return `${networkPrefix}${bold(cyan(toDisplayUrl(address)))}`;
}
});
}
Expand Down