Skip to content

Commit

Permalink
Merge pull request #329 from QuietMisdreavus/search-index-resource
Browse files Browse the repository at this point in the history
serve all in-crate js files
  • Loading branch information
QuietMisdreavus authored Apr 29, 2019
2 parents 46fa554 + a24b37a commit a31865e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
9 changes: 0 additions & 9 deletions src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,12 @@ 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/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");
Expand Down
9 changes: 9 additions & 0 deletions src/web/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
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"));
Expand Down

0 comments on commit a31865e

Please sign in to comment.