Search code examples
asp.net-coredocfx

docfx menu missing "Articles", "Api Documentation" when hosted from filesystem but show up on localhost:8080


When I run docfx docfx.json --serve and go to localhost:8080, I see two items on the top menu: "Articles" and "Api Documentation". When I navigate in the filesystem to _site\ and click on index.html to open it in Chrome, these menu items are missing. How can I make sure the menu is properly set when I run it as a static site?

I need to be able to package the html files and send them to people for them to view locally without them having to download the repo and install docFX.


Solution

  • Reason: The page needs extra JS files to the navigation bar, but it is blocked by Chrome. You can see these errors in Chrome console (F12):

    docfx.vendor.js:4 Access to XMLHttpRequest at 'file:///C:/git/docfx-seed/_site/toc.html' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
    send @ docfx.vendor.js:4
    docfx.vendor.js:4 Access to XMLHttpRequest at 'file:///C:/git/docfx-seed/_site/logo.svg' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
    

    Solution: Use template statictoc, which already embedded all the required parts into HTML file:

    docfx docfx.json -t statictoc