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

serve all in-crate js files #329

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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