Skip to content

feat: Implement --use-index & SPA flags #374

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

Closed
wants to merge 40 commits into from

Conversation

Antosser
Copy link
Contributor

Implemented the --use-index flag. If the path matches a directory and an index.html is found inside, the index.html gets sent instead of the explorer of the directory.

Implemented the --spa flag. If a file/directory is not found, the index.html in the root gets sent. The existence of index.html in the root is also checked at startup. An error is thrown otherwise:

        if config.spa() {
            let mut index_html = config.root_dir();
            index_html.push("index.html");

            if !index_html.exists() {
                eprintln!(
                    "{}",
                    "SPA flag is enabled, but index.html in root does not exist. Quitting...".red()
                );
                exit(1);
            }
        }

The docs were updated to match the new changes

@LeoBorai
Copy link
Member

@Antosser can we have 2 PRs for this? And tests as well please?

Its easier to review and to ensure everything is working as expected.

@Antosser
Copy link
Contributor Author

Antosser commented Oct 30, 2023

@Antosser can we have 2 PRs for this? And tests as well please?

Its easier to review and to ensure everything is working as expected.

To split this up into 2 PRs, the second will need to come after the first one. They cannot coexist, because of potential merge conflicts. It would be faster to leave this PR as is. I can write test though.

@Antosser
Copy link
Contributor Author

Antosser commented Oct 30, 2023

Why do the integration tests not get ran?

Edit: And why do 7 of them fail

@Antosser
Copy link
Contributor Author

Antosser commented Oct 30, 2023

An integration test is the right type of test to test the --spa and --use-index flag. However, I do not understand why they do not get run if you do cargo test. Also, given from what I've read, the #[cfg(test)], the mod ... {, and the mod.rs file inside tests, seem unnecessary, see the docs

@Antosser
Copy link
Contributor Author

I still need an answer

@LeoBorai
Copy link
Member

An integration test is the right type of test to test the --spa and --use-index flag. However, I do not understand why they do not get run if you do cargo test. Also, given from what I've read, the #[cfg(test)], the mod ... {, and the mod.rs file inside tests, seem unnecessary, see the docs

Hey @Antosser!

I recommend reading the workflow files to understand how every test is executed.

With regards to the organization of tests, I suggest leaving them as they are and discuss about them separately.

Lately, for E2E testing I would use something like Bats. I could set in up for you and leave a couple examples for you to follow and apply on this PR.

@Antosser
Copy link
Contributor Author

I recommend reading the workflow files to understand how every test is executed.

Do you mean the GitHub workflow files or the scripts?

Lately, for E2E testing I would use something like Bats

Bats, as in .bat files? Couldn't finds anything else with this name

@LeoBorai LeoBorai mentioned this pull request Nov 18, 2023
2 tasks
LeoBorai and others added 3 commits November 19, 2023 00:56
<!--
Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
-->

Provide tests workflow for CI

---

### Dependants

- [ ] http-server-rs#402 
- [ ] http-server-rs#374
@Antosser
Copy link
Contributor Author

Antosser commented Nov 22, 2023

@EstebanBorai

I want to say that the reason people use this app is that it is the rust alternative to NPM's http-server. People expect, that it is blazingly fast, very reliable, easy to use, and feature-rich. It has to represent the Rust community very well. That's why I want to make this app as friendly and easy to use as possible.

The purpose of NPM's http-server is to quickly set up an HTTP server to host HTML files, and that's the default. In my opinion, we should make that the default too and replace the --index flag with an --explorer flag.

I really want to add new features, but have no interest in writing non-rust bats tests. Can you please write them, so I can move on to other features without worrying about merge conflicts? Also, please consider using index.htmls by default.

Thanks for the overall help!

<!--
Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
-->
@Antosser
Copy link
Contributor Author

I love git

@LeoBorai
Copy link
Member

I love git

LOL

@LeoBorai
Copy link
Member

@Antosser can we have workflow changes in a separato PR please?

Copy link
Member

@LeoBorai LeoBorai left a comment

Choose a reason for hiding this comment

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

Lets move changes not related to SPA/index to a separate PR please!

Copy link
Member

Choose a reason for hiding this comment

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

Move to a scoped PR please!

Copy link
Member

Choose a reason for hiding this comment

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

Move to a scoped PR please!

Copy link
Member

Choose a reason for hiding this comment

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

Move to a scoped PR please!

Copy link
Member

Choose a reason for hiding this comment

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

Move to a scoped PR please!

LICENSE-MIT Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Can we have a specific PR for these updates? Im trying to narrow down this PR scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't remember ever changing the license.

README.md Outdated
Copy link
Member

Choose a reason for hiding this comment

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

I think its okay to add these changes as part of the LICENSE PR!

Cargo.toml Outdated
@@ -58,6 +58,7 @@ tokio = { version = "1.29.1", features = [
tokio-rustls = "0.23.4"
toml = "0.7.6"
humansize = "2.1.3"
colored = "2.0.4"
Copy link
Member

Choose a reason for hiding this comment

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

Can we add colors in another PR? So we revisit all places and keep UI consistent?

@Antosser
Copy link
Contributor Author

I never changed any of the workflow files, but it still looks like I changed them in this PR

@LeoBorai
Copy link
Member

I never changed any of the workflow files, but it still looks like I changed them in this PR

I think it has a couple issues while rebasing!

@LeoBorai
Copy link
Member

Perhaphs you can delete those workflow files from your PR?

@Antosser
Copy link
Contributor Author

Perhaphs you can delete those workflow files from your PR?

If I delete them, and you merge the PR, they will also disappear in the main branch.
At this point, I have no idea how to fix this PR. I'll just copy/paste the changes I actually made into a new PR

@Antosser
Copy link
Contributor Author

@EstebanBorai Can I make the --index flag the default and replace it with a --explorer flag? Better to know now before making changes I would have to change again later

@LeoBorai
Copy link
Member

@EstebanBorai Can I make the --index flag the default and replace it with a --explorer flag? Better to know now before making changes I would have to change again later

I would stick to current approach for now. I dont want to introduce unexpected changes for v0.

I have plans to move into Axum for a v1. I think this change of behavior will fit just fine when on Axum!

@LeoBorai
Copy link
Member

Perhaphs you can delete those workflow files from your PR?

If I delete them, and you merge the PR, they will also disappear in the main branch. At this point, I have no idea how to fix this PR. I'll just copy/paste the changes I actually made into a new PR

SGTM

@Antosser
Copy link
Contributor Author

@EstebanBorai Can I make the --index flag the default and replace it with a --explorer flag? Better to know now before making changes I would have to change again later

I would stick to current approach for now. I dont want to introduce unexpected changes for v0.

I have plans to move into Axum for a v1. I think this change of behavior will fit just fine when on Axum!

aight

@Antosser Antosser closed this Feb 25, 2024
@Antosser Antosser deleted the indexhtml branch February 27, 2024 17:49
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.

2 participants