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

fix: use same host for websocket server as for http server when previewing locally #1309

Merged
merged 3 commits into from
Oct 26, 2023

Conversation

f3ng3r
Copy link
Contributor

@f3ng3r f3ng3r commented Oct 24, 2023

What/Why/How?

Today the WS server used for hot reloading is initialized without specifying a host. But in the hot.js file, 127.0.0.1 is hardcoded as the host it should connect to. This breaks in some cases, such as when the websocket server binds to ipv6, and therefore isn't available on 127.0.0.1.

This PR changes it so that the host provided via --host or -h is passed on to the WS server as well, not only to the http server. It also adds this host as a global variable, alongside the wsPort variable, so that hot.js can pick up the correct host when connecting to the websocket; instead of the hardcoded host today.

Testing

No tests seem to exist for the preview-server functionality and I have not added any. Instead I have tested manually with a variety of commonly used hosts (::, 0.0.0.0, ::1, localhost, 127.0.0.1) to confirm that they work.

Check yourself

  • Code is linted
  • Tested with redoc/reference-docs/workflows (internal)
  • All new/updated code is covered with tests

Security

  • Security impact of change has been considered
  • Code follows company security practices and guidelines

@f3ng3r f3ng3r requested a review from a team as a code owner October 24, 2023 14:19
@changeset-bot
Copy link

changeset-bot bot commented Oct 24, 2023

🦋 Changeset detected

Latest commit: c956f51

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@redocly/cli Patch
@redocly/openapi-core Patch

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

@tatomyr
Copy link
Contributor

tatomyr commented Oct 24, 2023

Hi @f3ng3r!
Thank you for your contribution! Will take a look at this shortly.

Copy link
Contributor

@IgorKarpiuk IgorKarpiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Could you check if any docs need to be updated?

@tatomyr tatomyr force-pushed the fix/use-same-host-for-ws-server branch from 2e53c5c to c956f51 Compare October 26, 2023 11:42
@tatomyr tatomyr merged commit 73d96a2 into Redocly:main Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants