docsify icon indicating copy to clipboard operation
docsify copied to clipboard

404 error with a different http server for sidebar files

Open CxRes opened this issue 3 years ago • 11 comments

Bug Report

I am using a different server than the one provided by docsify-cli (http-server) because of docsifyjs/docsify-cli#32. I find that the server keeps complaining about missing sidebar file for each route even though I have set a global sidebar file. Like so:

 "GET foo/docs/bar/_sidebar.md" Error (404): "Not found"

The pages however work fine with the global sidebar loaded.

Steps to reproduce

Configurations that I have tried:

  1. Original Files are in /foo/docs Homepage is /foo/docs/bar/README.md I have a static sidebar at /foo/docs/_sidebar.md
window.$docsify = {
      name: 'foo',
      alias: {
        '/':'/bar/',
      },
      basePath: '/foo/docs/',
      relativePath: false,
      loadSidebar: '_sidebar.md',
     ...
}

1a.

window.$docsify = {
      name: 'foo',
      alias: {
        '/':'/bar/',
      },
      basePath: '/foo/docs/',
      relativePath: false,
      loadSidebar: '/_sidebar.md', //explicit slash
     ...
}
window.$docsify = {
      name: 'foo',
      alias: {
        '/':'/bar/',
        '/.*/_sidebar.md': '/_sidebar.md', // alias as in docs
      },
      basePath: '/foo/docs/',
      relativePath: false,
      loadSidebar: '_sidebar.md',
     ...
}
window.$docsify = {
      name: 'foo',
      alias: {
        '/':'/bar/',
        '/foo/docs/.*/_sidebar.md': '/foo/docs/_sidebar.md', // full alias which is probably incorrect
      },
      basePath: '/foo/docs/',
      relativePath: false,
      loadSidebar: '_sidebar.md',
     ...
}

In each of these cases, I get the 404 error.

What is current behaviour

There is an 404 error message for missing sidebar for each route, even when a global sidebar is defined.

What is the expected behaviour

There should be no error message! Docsify should not look for a local sidebar file.

Other relevant information

  • [ ] Bug does still occur when all/other plugins are disabled?

  • Your OS: Windows 10 x64

  • Node.js version: 14.17.5

  • npm/yarn version: 6.14.14

  • Browser version: Version 1.33.106 Chromium: 96.0.4664.110 (Official Build) (64-bit)

  • Docsify version: 4.12.1

  • Docsify plugins: None

Please create a reproducible sandbox

Cannot do so, as I need to change how the page is served. Help appreciated.

CxRes avatar Jan 05 '22 23:01 CxRes

where is your index.html? in /foo/docs/ or /foo/ if your index.html in /foo/ Configurations blow can work

window.$docsify = {
  name: "foo",
  alias: {
    "/bar/": "/",
  },
  basePath: "/docs/",
  loadSidebar: "_sidebar.md",
  homepage: "README.md",
  ...
}

kxh4892636 avatar Jan 06 '22 13:01 kxh4892636

where is your index.html? in /foo/docs/ or /foo/ if your index.html in /foo/ Configurations blow can work

Sorry it was not clear but as I said above, files are in /oo/docs/ including index.html. The configuration works fine in that my page loads, except I get 404 error for missing sidebar for each and every route like for /foo/docs/bar/_sidebar.md or /foo/docs/baz/_sidebar.md. Docsify simply should not even be looking for these routes with loadSidebar specified as a file and exclusively look at /foo/docs/_sidebar.md for all routes. (that's why I classify this a bug)!

CxRes avatar Jan 06 '22 17:01 CxRes

you can read https://docsify.js.org/#/more-pages?id=nested-sidebars. you configure

alias: {
    "/": "/bar/",
  },

when you look at /foo/docs/_sidebar.md, you will redirect /foo/docs/bar/_sidrbar.md, so you get 404 error. So delete it and modify homePage : "/bar/README.md". Configurations below can work

window.$docsify = {
  name: "foo",
  loadSidebar: "_sidebar.md",
  homepage: "/bar/README.md",

kxh4892636 avatar Jan 07 '22 09:01 kxh4892636

If I understand correctly, you've specified a specific sidebar, so it should not try to find side bar files based on your current path. I believe this should be improved.

trusktr avatar Jan 12 '22 04:01 trusktr

I believe I am running into this issue too. Using c4Builder which use docsify it is generating a docsify site with sidebar. The top level pages all work perfectly. But any page in a subdirectory gets 404 for the _sidebar.md file and there is 1 request made per level of nesting. These requests are all initiated from the docsify/lib/docsify.min.js code.

Not sure if there is some setting which c4Builder needs to set when call docsify or if I am just hitting this issue.

GregEisenberg avatar Feb 17 '22 01:02 GregEisenberg

Try setting alias

        alias: {
            '/.*/_sidebar.md': '/_sidebar.md'
        },

sy-records avatar Feb 17 '22 01:02 sy-records

Thanks @sy-records for your FAST reply. I was able to set "alias": { '/.*/_sidebar.md': '/_sidebar.md' }, in the JSON object called window.$docsify in index.html and that does seem to solve the issue. However since I am using the c4Builder which calls docsify and generates the index.html I will have to figure out how to get this included by default.

Was I correct in adding to the window.$docsify object in index.html? Was there some other place to add it?

Thanks again!

GregEisenberg avatar Feb 17 '22 01:02 GregEisenberg

@sy-records Thanks!

phoenixweiss avatar Apr 13 '22 20:04 phoenixweiss

@sy-records Could you please take a few minutes to see why this sidebar is not loading cased by a 404 error of _sidebar.md?

  • site: https://qpod0.github.io/fyi/#/
  • source code: https://github.com/QPod0/fyi/tree/main/docs

I've tried both GitHub Actions and Deploy from a branch.

QPod0 avatar Feb 06 '24 14:02 QPod0

@QPod0 No GitHub Actions is required, no Jekyll theme needs to be set, just open the page, select the corresponding branch and directory.

image

sy-records avatar Feb 07 '24 01:02 sy-records

Thanks @sy-records ! It now works well.

QPod0 avatar Feb 07 '24 06:02 QPod0