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

Add server_listening reporter event with actually-bound port and address #1274

Closed
wants to merge 1 commit into from

Conversation

robhogan
Copy link
Contributor

Summary

Add a server_listening reporter event. This serves two purposes:

Expose actually-bound port and address when input configuration is more ambiguous

Metro may already be configured to start on an ephemeral (OS-assigned) port, if configured with --port 0, however Metro doesn't report or expose which port was actually assigned - the initialize_done reporter event repeats the configured port.

(h/t @kmagiera who let us know about this at React Conf ⚛️)

Similarly, when Metro is configured to start on localhost, it doesn't expose whether it binds to IPv6 (potentially dual stack) or (exclusively) IPv4.

Report when Metro is first ready to accept HTTP requests

Metro may be listening before the transformer is fully initialised or the file crawl is complete - but this is safe, because request handlers wait for bundler readiness. We may in future start listening earlier in the startup process so that Metro is available to at least start queueing requests as soon as possible.

Integrators may use server_listening as an explicit signal that Metro is ready to accept http requests, even though it may not be fully warm.

Changelog

 - **[Feature]**: Add `server_listening` reporter event, exposing bound port, address and family.

Test plan

With console.log(event) added to TerminalReporter for server_listening:

yarn start serve --port 0
yarn run v1.22.19
$ node packages/metro/src/cli serve --port 0

                        ▒▒▓▓▓▓▒▒
                     ▒▓▓▓▒▒░░▒▒▓▓▓▒
                  ▒▓▓▓▓░░░▒▒▒▒░░░▓▓▓▓▒
                 ▓▓▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▒▒▒▓▓
                 ▓▓░░░░░▒▓▓▓▓▓▓▒░░░░░▓▓
                 ▓▓░░▓▓▒░░░▒▒░░░▒▓▒░░▓▓
                 ▓▓░░▓▓▓▓▓▒▒▒▒▓▓▓▓▒░░▓▓
                 ▓▓░░▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░▓▓
                 ▓▓▒░░▒▒▓▓▓▓▓▓▓▓▒░░░▒▓▓
                  ▒▓▓▓▒░░░▒▓▓▒░░░▒▓▓▓▒
                     ▒▓▓▓▒░░░░▒▓▓▓▒
                        ▒▒▓▓▓▓▒▒


{
  type: 'server_listening',
  address: '::1',
  port: 57182,
  family: 'IPv6'
}
                Welcome to Metro v0.80.9
              Fast - Scalable - Integrated

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 17, 2024
@facebook-github-bot
Copy link
Contributor

@robhogan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.83%. Comparing base (57607bf) to head (6bd5d2b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1274   +/-   ##
=======================================
  Coverage   83.83%   83.83%           
=======================================
  Files         207      207           
  Lines       10819    10821    +2     
  Branches     2702     2702           
=======================================
+ Hits         9070     9072    +2     
  Misses       1749     1749           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@facebook-github-bot
Copy link
Contributor

@robhogan merged this pull request in 6856d00.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants