http-server-rs / http-server

Simple and configurable command-line HTTP server
https://crates.io/crates/http-server
Apache License 2.0
176 stars 20 forks source link

Option to disable file browsing #417

Open ratulb opened 6 months ago

ratulb commented 6 months ago

Description

Could not find anywhere an option to open the index.html page when user opens localhost:7878. How do we do that?

Most of the cases - when we access the server with localhost:7878, we expect to see the home page - not the file system. Of course - file browsing is useful but it should be configurable.

Is there a configuration? Documentation says - by default it is enabled. Did not see an option to disable.

EstebanBorai commented 6 months ago

Hey @ratulb!

Yes you are right, we need a way to run the server without serving the FileExplorer.

Perhaps to keep backwards compatibilty we could have a --no-explorer?

Let me know your thoughts! And if you are willing toxgive it a shot!

ratulb commented 6 months ago

Thanks for your prompt response. I would like to give it a shot very much.

It would be helpful if you could spare some time pointing me in the right direction where changes would be needed.


From: Esteban Borai @.> Sent: Sunday, February 18, 2024 11:51 PM To: http-server-rs/http-server @.> Cc: Ratul @.>; Mention @.> Subject: Re: [http-server-rs/http-server] Option to disable file browsing (Issue #417)

Hey @ratulbhttps://github.com/ratulb!

Yes you are right, we need a way to run the server without serving the FileExplorer.

Perhaps to keep backwards compatibilty we could have a --no-explorer?

Let me know your thoughts! And if you are willing toxgive it a shot!

— Reply to this email directly, view it on GitHubhttps://github.com/http-server-rs/http-server/issues/417#issuecomment-1951405829, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAM3HO3YCFNQLJKCZFZNPLTYUJBBDAVCNFSM6AAAAABDOHP6X6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJRGQYDKOBSHE. You are receiving this because you were mentioned.Message ID: @.***>

Antosser commented 6 months ago

I already made a pull request for this exact feature here: https://github.com/http-server-rs/http-server/pull/374 . I called the flag--use-index but you can easily rename it to anything else

P.S. Please follow up on the testing framework discussion

Antosser commented 6 months ago

Hey @ratulb!

Yes you are right, we need a way to run the server without serving the FileExplorer.

Perhaps to keep backwards compatibilty we could have a --no-explorer?

Let me know your thoughts! And if you are willing toxgive it a shot!

I'd go one step further and make that the default. This isn't a library, so it wouldn't be a "breaking" change, and I'd argue that much more people would use this app for html sites than as an explorer in the browser. In other words, I wouldn't be concerned about backwards compatibility

ratulb commented 6 months ago

I already made a pull request for this exact feature here: #374 . I called the flag--use-index but you can easily rename it to anything else

P.S. Please follow up on the testing framework discussion

--no-explorer sounds explicit in it's intent without breaking any existing setups. In a major release later - we could drop this flag all together making it the default behaviour - and could introduce a shorter --explorer flag which would retain current behaviour!

Antosser commented 6 months ago

--no-explorer sounds explicit in it's intent without breaking any existing setups.

I don't think it's necessary for this feature to disable the explorer. Automatically loading index.html in the directory should be enough. If you go to a path without an index.html, why not just fall back to the explorer instead of dropping a 404 page.

EstebanBorai commented 6 months ago

I already made a pull request for this exact feature here: #374 . I called the flag--use-index but you can easily rename it to anything else P.S. Please follow up on the testing framework discussion

--no-explorer sounds explicit in it's intent without breaking any existing setups. In a major release later - we could drop this flag all together making it the default behaviour - and could introduce a shorter --explorer flag which would retain current behaviour!

Agree! Its always a good practice to maintain backwards compatibility. In a second version (perhaps Axum migration), we could consider the proposal by @Antosser IMHO.

ratulb commented 6 months ago

--no-explorer sounds explicit in it's intent without breaking any existing setups.

I don't think it's necessary for this feature to disable the explorer. Automatically loading index.html in the directory should be enough. If you go to a path without an index.html, why not just fall back to the explorer instead of dropping a 404 page.

I meant if explicitly not enabled - explorer behaviour should not be available.

command: http-server #server started with explorer feature disabled Ideally, localhost:7878 -> Show index.html - if present else 404 localhost:7878/index.html -> Show index.html - if present else 404 localhost:7878/a.html -> Show a.html - if present else 404 localhost:7878/a/b.html -> Show a/b.html - if present else 404

command: http-server --explorer #server started with explorer feature enabled

localhost:7878 -> Show index.html - if present else explorer localhost:7878/index.html -> Show index.html - if present else explorer localhost:7878/a.html -> Show a.html - if present else explorer localhost:7878/a/b.html -> Show a/b.html - if present else explorer

Would like to hear more from you guys.

Antosser commented 6 months ago

I meant if explicitly not enabled - explorer behaviour should not be available.

Why not just leave it in if the path is an existing directory without an index.html? Won't mess anything up and that's how Node's http-server works, so people are kinda going to expect that

EstebanBorai commented 6 months ago

Hi @ratulb and @Antosser!

I think we have a valuable discussion here, what do you guys think about working together on polishing this feature in @Antosser PR https://github.com/http-server-rs/http-server/pull/374 via code review?

ratulb commented 6 months ago

Tied up with a GA release. Would need to come back.

@Antosserhttps://github.com/Antosser?


From: Esteban Borai @.> Sent: Saturday, February 24, 2024 9:49 AM To: http-server-rs/http-server @.> Cc: Ratul @.>; Mention @.> Subject: Re: [http-server-rs/http-server] Option to disable file browsing (Issue #417)

Hi @ratulbhttps://github.com/ratulb and @Antosserhttps://github.com/Antosser!

I think we have a valuable discussion here, what do you guys think about working together on polishing this feature in @Antosserhttps://github.com/Antosser PR #374https://github.com/http-server-rs/http-server/pull/374 via code review?

— Reply to this email directly, view it on GitHubhttps://github.com/http-server-rs/http-server/issues/417#issuecomment-1962247117, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAM3HOYQTLQAJPHMESNRYQLYVFS3JAVCNFSM6AAAAABDOHP6X6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRSGI2DOMJRG4. You are receiving this because you were mentioned.Message ID: @.***>

Antosser commented 6 months ago

Is this issue now resolved? Technically, we didn't make a flag, which disables the explorer, but showing a 404 page instead of an explorer if there's no index.html would be less informative and wouldn't be useful