Skip to content

Commit a31865e

Browse files
Merge pull request #329 from QuietMisdreavus/search-index-resource
serve all in-crate js files
2 parents 46fa554 + a24b37a commit a31865e

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/web/mod.rs

-9
Original file line numberDiff line numberDiff line change
@@ -170,21 +170,12 @@ impl CratesfyiHandler {
170170
router.get("/:crate/:version/",
171171
rustdoc::rustdoc_redirector_handler,
172172
"crate_version_");
173-
router.get("/:crate/:version/search-index.js",
174-
rustdoc::rustdoc_html_server_handler,
175-
"crate_version_search_index_js");
176173
router.get("/:crate/:version/settings.html",
177174
rustdoc::rustdoc_html_server_handler,
178175
"crate_version_settings_html");
179176
router.get("/:crate/:version/all.html",
180177
rustdoc::rustdoc_html_server_handler,
181178
"crate_version_all_html");
182-
router.get("/:crate/:version/aliases.js",
183-
rustdoc::rustdoc_html_server_handler,
184-
"crate_version_aliases_js");
185-
router.get("/:crate/:version/source-files.js",
186-
rustdoc::rustdoc_html_server_handler,
187-
"crate_version_source_files_js");
188179
router.get("/:crate/:version/:target",
189180
rustdoc::rustdoc_redirector_handler,
190181
"crate_version_target");

src/web/rustdoc.rs

+9
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ pub fn rustdoc_redirector_handler(req: &mut Request) -> IronResult<Response> {
104104
Ok(resp)
105105
}
106106

107+
// this unwrap is safe because iron urls are always able to use `path_segments`
108+
// i'm using this instead of `req.url.path()` to avoid allocating the Vec, and also to avoid
109+
// keeping the borrow alive into the return statement
110+
if req.url.as_ref().path_segments().unwrap().last().map_or(false, |s| s.ends_with(".js")) {
111+
// javascript files should be handled by the file server instead of erroneously
112+
// redirecting to the crate root page
113+
return rustdoc_html_server_handler(req);
114+
}
115+
107116
let router = extension!(req, Router);
108117
// this handler should never called without crate pattern
109118
let crate_name = cexpect!(router.find("crate"));

0 commit comments

Comments
 (0)