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

fix: Cannot serve off /.../index.html #1372

Merged

Conversation

rgladwell
Copy link
Contributor

@rgladwell rgladwell commented Sep 12, 2020

Summary

fixes #427

Docsify must be hosted on a server that supports a default directory index (i.e. maps /.../ -> /.../index.html).

Some platforms do not support this, however. For example, HTML apps hosted on the popular game/software platform, Itch.io.

This change supports hosting Docsify off an explicit path file, such as /index.html. It does this by:

  1. Preventing the /index.html part of the path being removed during routing, and
  2. Ensuring we can retrieve the source markdown using explicit path file URIs.

For example, http://example.org/index.html#/blah would be mapped to the markdown source file http://example.org/blah.md.

This fixes:

#427

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Build-related changes
  • Repo settings
  • Other, please describe:

If changing the UI of default theme, please provide the before/after screenshot:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)

You have tested in the following browsers: (Providing a detailed version will be better.)

  • Chrome
  • Firefox
  • Safari
  • Edge
  • IE

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature
  • Related documents have been updated
  • Related tests have been updated

To avoid wasting your time, it's best to open a feature request issue first and wait for approval before working on it.

@vercel
Copy link

vercel bot commented Sep 12, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/docsify-core/docsify-preview/1nszbjtkr
✅ Preview: https://docsify-previe-git-fork-rgladwell-fix-base-path-file-not-f15f74.docsify-core.vercel.app

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 12, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit d94d259:

Sandbox Source
docsify-template Configuration

@rgladwell
Copy link
Contributor Author

The e2e tests are reported by CI as failing, but are passing locally for me.

Copy link
Member

@anikethsaha anikethsaha left a comment

Choose a reason for hiding this comment

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

Thanks a lot for fixing the bug.

It does seems to work and fixes the issue.

Few questions

  • It would be great to have some more test cases.
  • it would be great to have some comments for why we are doing those normalizing and those conditional check. May be linking to the issues/PR will work as well.

Also, I doubt this might be a semver-major as it can be a breaking change. cc @docsifyjs/reviewers

@rgladwell
Copy link
Contributor Author

@anikethsaha Thanks for the feedback. Could you clarify what sort of test cases you are looking for? I notice you have Cypress and unit tests. Which would you prefer, and where would they go exactly?

@anikethsaha
Copy link
Member

anikethsaha commented Sep 15, 2020

@anikethsaha Thanks for the feedback. Could you clarify what sort of test cases you are looking for? I notice you have Cypress and unit tests. Which would you prefer, and where would they go exactly?

You could add cypress tests for other links like

/index.md
/index.html#/
/#/index.html/
/index.html/#/ (it would be 404 but still good to cover. )

Also if there are other cases you think you can add

@rgladwell
Copy link
Contributor Author

@anikethsaha You could add cypress tests for other links like

Done, let me know if they're sufficient.

Copy link
Member

@anikethsaha anikethsaha left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

My only concern is whether this should be considered as breaking or not!

@rgladwell
Copy link
Contributor Author

It shouldn't be breaking, it's an additive change. You could argue that any breakages would be bugs.

Copy link
Member

@Koooooo-7 Koooooo-7 left a comment

Choose a reason for hiding this comment

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

@anikethsaha I think when it is not sure if it is a breaking change, we can make it as an option.
Giving the switch button to users' hands.:)

@rgladwell
Copy link
Contributor Author

rgladwell commented Sep 17, 2020

Hmmm I think this change breaks live reloads in development mode.

anikethsaha
anikethsaha previously approved these changes Sep 18, 2020
@anikethsaha
Copy link
Member

I agree that it is not a breaking change as it was a bug so probably it wasn't used before in order to avoid the bug.

@rgladwell
Copy link
Contributor Author

Been trying to add a feature flag for this, but the code is getting very complicated. If this isn't a breaking change, can we live without it?

@anikethsaha
Copy link
Member

cc @docsifyjs/core

@jhildenbiddle
Copy link
Member

Hey @rgladwell,

Thanks for the PR!

We recently merged #1276 into develop which is an overhaul of our CI and local test environments. As a result, the e2e tests in this PR will need to rewritten in Jest+Playwright instead of Cypress. The good news is that the test environments should be more stable and easier to work with. The PR contains a summary of the changes, help is available in /test/README.md directory, and I'm available if you have any questions.

@rgladwell
Copy link
Contributor Author

Is there some way to get a screenshot or run non-headless for the Jest e2e tests?

Docsify must be hosted on a server that supports a default directory
index (i.e. maps `/.../` -> `/.../index.html`).

Some platforms do not support this, however. For example, HTML apps
hosted on the popular game/software platform, Itch.io.

This change supports hosting Docsify off an explicit path file, such as
`/index.html`. It does this by:

 1. Adding handling for paths like `index.html#/blah`, and
 2. Normalising paths with fragments back to markdown paths

For example, `http://example.org/index.html#/blah` would be mapped to
`http://example.org/blah.md`.

This fixes:

docsifyjs#427
@rgladwell
Copy link
Contributor Author

@jhildenbiddle @anikethsaha @Koooooo-7 As requested, added e2e tests using Jest framework.

@jhildenbiddle jhildenbiddle requested a review from a team February 5, 2021 16:20
src/core/router/history/hash.js Outdated Show resolved Hide resolved
Copy link
Member

@sy-records sy-records left a comment

Choose a reason for hiding this comment

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

LGTM.

note: Please use squash and merge for merging

@sy-records sy-records changed the title Fix #427: Cannot serve off /.../index.html fix: Cannot serve off /.../index.html Feb 7, 2021
@Koooooo-7 Koooooo-7 requested a review from a team February 7, 2021 07:35
@jhildenbiddle jhildenbiddle merged commit 759ffac into docsifyjs:develop Feb 7, 2021
@rgladwell rgladwell deleted the fix-base-path-file-not-folder branch February 7, 2021 16:26
@rgladwell
Copy link
Contributor Author

Thanks!

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.

Fix bug where URI path is to a file and not to directory
5 participants