From a83da34a42a81412ce96af2678d84e35030e39e0 Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Fri, 12 Apr 2019 15:24:35 -0500 Subject: [PATCH 1/2] serve all in-crate js files starting with rust-lang/rust#59776, the search index, aliases, and source file list are getting the resource suffix added to their file names. this means we can't route them from a static path any more. since we always check the static file router first, this will still allow serving `main.js` for rustdoc versions prior to the addition of `--static-root-path`, and also allows rustdoc to add per-crate javascript files without requiring docs.rs to update to handle it. (it also allows us to start hosting things *other* than rustdoc output as docs - e.g. mdbook output - in the future without changing the routing table massively.) --- src/web/mod.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/web/mod.rs b/src/web/mod.rs index c094eba70..9452981aa 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -170,21 +170,15 @@ impl CratesfyiHandler { router.get("/:crate/:version/", rustdoc::rustdoc_redirector_handler, "crate_version_"); - router.get("/:crate/:version/search-index.js", - rustdoc::rustdoc_html_server_handler, - "crate_version_search_index_js"); + router.get("/:crate/:version/*.js", + rustdoc::rustdoc_redirector_handler, + "crate_version_js"); router.get("/:crate/:version/settings.html", rustdoc::rustdoc_html_server_handler, "crate_version_settings_html"); router.get("/:crate/:version/all.html", rustdoc::rustdoc_html_server_handler, "crate_version_all_html"); - router.get("/:crate/:version/aliases.js", - rustdoc::rustdoc_html_server_handler, - "crate_version_aliases_js"); - router.get("/:crate/:version/source-files.js", - rustdoc::rustdoc_html_server_handler, - "crate_version_source_files_js"); router.get("/:crate/:version/:target", rustdoc::rustdoc_redirector_handler, "crate_version_target"); From a24b37a93d54f12e79ea9e39e3d6f56b9951be75 Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Mon, 29 Apr 2019 10:38:33 -0500 Subject: [PATCH 2/2] tweak how in-crate javascript files are served --- src/web/mod.rs | 3 --- src/web/rustdoc.rs | 9 +++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/web/mod.rs b/src/web/mod.rs index 9452981aa..5b9fe199e 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -170,9 +170,6 @@ impl CratesfyiHandler { router.get("/:crate/:version/", rustdoc::rustdoc_redirector_handler, "crate_version_"); - router.get("/:crate/:version/*.js", - rustdoc::rustdoc_redirector_handler, - "crate_version_js"); router.get("/:crate/:version/settings.html", rustdoc::rustdoc_html_server_handler, "crate_version_settings_html"); diff --git a/src/web/rustdoc.rs b/src/web/rustdoc.rs index d9a3f2d87..5bba8387e 100644 --- a/src/web/rustdoc.rs +++ b/src/web/rustdoc.rs @@ -104,6 +104,15 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult { Ok(resp) } + // this unwrap is safe because iron urls are always able to use `path_segments` + // i'm using this instead of `req.url.path()` to avoid allocating the Vec, and also to avoid + // keeping the borrow alive into the return statement + if req.url.as_ref().path_segments().unwrap().last().map_or(false, |s| s.ends_with(".js")) { + // javascript files should be handled by the file server instead of erroneously + // redirecting to the crate root page + return rustdoc_html_server_handler(req); + } + let router = extension!(req, Router); // this handler should never called without crate pattern let crate_name = cexpect!(router.find("crate"));