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(http): file server prints local network address #4604

Merged
merged 7 commits into from Apr 22, 2024

Conversation

kt3k
Copy link
Member

@kt3k kt3k commented Apr 17, 2024

closes #4597

This PR updates onListen hook of file_server to show the local network IP address. The scripts shows 2 urls like the below (Updated):

$ deno run -A http/file_server.ts 
Listening on:
- Local: http://localhost:4507
- Network: http://192.168.79.163:4507

Suggestions to the output format are welcome


Note: npm:serve chooses non internal IPv4 address as the network address. This implementation follows it. ref. https://github.com/vercel/serve/blob/1ea55b1b5004f468159b54775e4fb3090fedbb2b/source/utilities/http.ts#L40

Note: Deno's NetworkInterfaceInfo object doesn't have internal field, but it's polyfilled as address.startsWith("127") in the node compat layer https://github.com/denoland/deno/blob/9acbf90b06bf79dd6e4cf2428b3566da009bed65/ext/node/polyfills/os.ts#L232-L234. This implementation follows it as well.

@github-actions github-actions bot added the http label Apr 17, 2024
Copy link

codecov bot commented Apr 17, 2024

Codecov Report

Attention: Patch coverage is 0% with 18 lines in your changes are missing coverage. Please review.

Project coverage is 90.93%. Comparing base (a6fe34b) to head (f9a4fc1).
Report is 222 commits behind head on main.

Files Patch % Lines
http/file_server.ts 0.00% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4604      +/-   ##
==========================================
- Coverage   91.23%   90.93%   -0.31%     
==========================================
  Files         478      475       -3     
  Lines       41465    37325    -4140     
  Branches     5225     5299      +74     
==========================================
- Hits        37832    33941    -3891     
+ Misses       3568     3330     -238     
+ Partials       65       54      -11     

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

@kt3k
Copy link
Member Author

kt3k commented Apr 17, 2024

Side note: This will prints ip address that is not useful to the user in Deno Deploy like:

Serving static files!
local: http://localhost:80
network: http://10.0.0.10:80

Copy link
Collaborator

@iuioiua iuioiua left a comment

Choose a reason for hiding this comment

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

Can you please add a test?

Side note: This will prints ip address that is not useful to the user in Deno Deploy like:

Serving static files!
local: http://localhost:80
network: http://10.0.0.10:80

This doesn't seem to be the case. The functionality added in this PR is only accessible when running the script directly via deno run -A jsr:@std/http/file-server because we're using import.meta.main.

http/file_server.ts Outdated Show resolved Hide resolved
http/file_server.ts Outdated Show resolved Hide resolved
@kt3k
Copy link
Member Author

kt3k commented Apr 18, 2024

This doesn't seem to be the case. The functionality added in this PR is only accessible when running the script directly via deno run -A jsr:@std/http/file-server because we're using import.meta.main.

file_server is often used as the entrypoint script in Deploy when serving static site. import.meta.main is true in that case. ref. https://github.com/search?q=path%3Adeploy.yml%20file_server.ts&type=code

We even optimize etag generation for Deno Deploy. #3186

@kt3k
Copy link
Member Author

kt3k commented Apr 18, 2024

Now this prints:

$ deno run -A http/file_server.ts 
Listening on:
- Local: http://localhost:4507
- Network: http://192.168.79.163:4507

Copy link
Collaborator

@iuioiua iuioiua left a comment

Choose a reason for hiding this comment

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

Testing of this script can be done another time. I created #4605 to track.

http/file_server.ts Outdated Show resolved Hide resolved
http/file_server_test.ts Show resolved Hide resolved
Comment on lines +987 to +989
const networkAdress = Deno.networkInterfaces().find((i) =>
i.family === "IPv4" && !i.address.startsWith("127")
)?.address;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like this should be used as the implementation for getNetworkAddress().

@iuioiua iuioiua changed the title feat(http): file_server prints local network address feat(http): file server prints local network address Apr 20, 2024
@kt3k kt3k merged commit 0d7e9fe into denoland:main Apr 22, 2024
14 checks passed
@kt3k kt3k deleted the file-server-show-network-address branch April 22, 2024 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[http/file_server] Show local network IP
2 participants