-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: Implement a way to expose static files from a directory (similar to Python SimpleHttpServer) #45079
Comments
FWIW we use the Python equivalent for the Lines 835 to 837 in eb298df
|
Nice! this way we can move from Python and use Node only for it 🤩 |
This looks great. I'm interested in seeing how the implementation goes. |
@nodejs/tsc @nodejs/http |
Same here, really interested in this. Let me know if I can help with the implementation. |
The maintainers of |
Good point at @GeoffreyBooth. @ErickWendel how much overlap will there be with the |
I don't think we should be implementing https://www.npmjs.com/package/http-server in core. |
You mean |
I think we should offer the functionality to serve static files in core, ideally with a superior implementation than @jasnell did some part of the work for http/2, however, it lacks quite a few features to be complete (etags, ranges, directories, etc). We might also provide some utility that could enable us to do: node -e "require('http').createStaticServe({ path: './static' }).listen(3000)" I don't think we should offer a |
What if we choose not to worry about configurability or efficiency? For example, what if it:
Valid use cases would be:
Invalid use cases would be:
|
That's exactly what I meant. Python's SimpleHTTPServer does the same. They have a big disclaimer saying that this module is just a util module for a development environment. Edited by Trott to preserve formatting in quoted material. |
We've had this discussion before (even though I can't find it right now). I frequently use |
Maybe |
|
I agree with this approach. One of the reasons to bring something into core is if the experience can be improved by having the feature in core. Implementing the serving in C++ would achieve that, because it's a hassle to work with packages that require compilation. I also think our goal should be something that could be used in production. The dev use case is already well handled by ecosystem packages that have more features than we're likely to want to add (hot module reload etc). |
A key challenge is the fact that sending a file efficiently varies across http1, http2, and http3. A sendfile like approach only really works with http1, where we are capable of writing directly to the socket, or can rely on the kernel to efficiently send the data from an fd. For http2 and http3 the situation is a lot different. We have to rely on the underlying nghttp2 and nghttp3 state model to determine exactly how and when to send various chunks of the file. It can be made very efficient, yes, but there's not a one impl fits all approach that is going to work. The suggestion of using something like I think before we do anything further here, we should work on finishing up landing the quic/http3 implementation, then work on normalizing the http1, 2, and 3 implementations as much as possible, identifying an API approach that will allow a consistent UX/DX for sending files. |
FWIW I have an HTTP 1.1 implementation in #45096. |
I believe the syntax proposed in #45096 might solve the compat issue mentioned by @jasnell with regards to http2, http3 since these can be supported under diff modules. While I would prefer seeing a C++ implementation with performance in mind as mentioned by @mcollina I'd be very much +1 to land an experimental JS implementation first and progress from there. Thanks @ErickWendel for bringing it up, it's great to see the momentum it managed to gather and would love to see that landing @aduh95 ❤️ |
+1 to planning for HTTP/2 and QUIC support ahead of time. |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment. For more information on how the project manages feature requests, please consult the feature request management document. |
There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the
never-stale
|
What is the problem this feature will solve?
HTTP Server is a very popular package with 1M+ weekly downloads used to expose static files from a directory.
Node.js doesn't have any native way to expose static files in a directory from a single command.
This is an idea given by @ruyadorno during a session on Tooling WG at nodejs/tooling#164 which he suggested I implement it.
What is the feature you are proposing to solve the problem?
In Python, they have the SimpleHTTPServer a native module meant for the development environment and has basic security checks.
The idea is not to replace the HTTP Server package, as it's a robust package, but to have a similar implementation to Python's SimpleHTTPServer exposing directory files.
Adding something like:
or
What alternatives have you considered?
No response
The text was updated successfully, but these errors were encountered: