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

Using the true option in server.host doesn't work #10264

Closed
1 task
patrikwalker opened this issue Feb 28, 2024 · 7 comments · Fixed by #10282
Closed
1 task

Using the true option in server.host doesn't work #10264

patrikwalker opened this issue Feb 28, 2024 · 7 comments · Fixed by #10282
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) good first issue Good for newcomers. If you need additional guidance, feel free to post in #dev on Discord pkg: node Related to Node adapter (scope)

Comments

@patrikwalker
Copy link

patrikwalker commented Feb 28, 2024

Astro Info

Astro                    v4.4.5
Node                     v20.11.1
System                   Linux (x64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/node
Integrations             @astrojs/alpinejs
                         @astrojs/tailwind

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

The server.host option with output: "server" option doesn't build the correct output when used with the true value. The resulting code just checks for typeof options.host === "boolean" and uses "localhost" in this case, not considering the actual value of the (boolean) option. The documentation states that true should instead result in listening to all addresses. Our current workaround is to just use "0.0.0.0" instead of true.

const hostOptions = typeof options.host === 'boolean' ? 'localhost' : options.host;

What's the expected result?

Setting the server.host option should result in a server listening to all addresses.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-pbnej2

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Feb 28, 2024
@lilnasy lilnasy added - P3: minor bug An edge case that only affects very specific usage (priority) - P2: nice to have Not breaking anything but nice to have (priority) pkg: node Related to Node adapter (scope) and removed needs triage Issue needs to be triaged - P2: nice to have Not breaking anything but nice to have (priority) labels Feb 28, 2024
@lilnasy
Copy link
Contributor

lilnasy commented Feb 28, 2024

Good first issue!

This is an opportunity for astro users to learn about how astro works by fixing a small but real bug. You can expect to get help setting up the dev environment, and understanding the project structure in #dev channel of our discord server (https://astro.build/chat).

What's the bug?

The node adapter listens on the wrong address when config.server.host is set to true.

What's going wrong here?

The node adapter reads config.server.host to decide what hostname to start the production server on, when a host is not explicitly provided. When this config is set to true, Vite dev server's behavior is to listen on 0.0.0.0. The node adapter fails to match this behavior, and instead falls back to the default: "localhost".

Where do I start looking?

The OP has already identified the relevant line of code in the issue description!

@SatanshuMishra
Copy link
Contributor

I would love to take a shot at working on this if that's alright! However, this is my first PR with in the astro repository, so I may need some guidance.

@ematipico ematipico added the good first issue Good for newcomers. If you need additional guidance, feel free to post in #dev on Discord label Feb 28, 2024
@ematipico
Copy link
Member

ematipico commented Feb 29, 2024

@SatanshuMishra The CONTRIBUTING.md is always a good place to start.

Any questions, feel free to make them here

@lilnasy
Copy link
Contributor

lilnasy commented Feb 29, 2024

A fix would be small and quick enough that assigning someone is not necessary.

@SatanshuMishra I am unassigning to keep this issue open to anyone who wants to create a PR.

@SatanshuMishra
Copy link
Contributor

Sounds good! I should have a PR up for this hopefully by the end of the day!

@lilnasy
Copy link
Contributor

lilnasy commented Feb 29, 2024

Oops, sorry for unassigning you. I wasn't sure if you were around. I could've waited longer. Sorry for undoing your assignment, @ematipico.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) good first issue Good for newcomers. If you need additional guidance, feel free to post in #dev on Discord pkg: node Related to Node adapter (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants