Skip to content

Commit 07a06ff

Browse files
Allow platforms async load to work on docs.rs crates pages
1 parent 66eee92 commit 07a06ff

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/web/crate_details.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ pub(crate) async fn get_all_platforms(
505505
Extension(pool): Extension<Pool>,
506506
uri: Uri,
507507
) -> AxumResult<AxumResponse> {
508-
let is_crate_root = uri.path().starts_with("/crate/");
508+
let is_crate_root = uri.path().starts_with("/-/menus/platforms/crate/");
509509
let req_path: String = params.path.unwrap_or_default();
510510
let req_path: Vec<&str> = req_path.split('/').collect();
511511

@@ -610,6 +610,11 @@ pub(crate) async fn get_all_platforms(
610610

611611
(target, inner_path.join("/"))
612612
};
613+
let inner_path = if inner_path.is_empty() {
614+
format!("{name}/index.html")
615+
} else {
616+
format!("{name}/{inner_path}")
617+
};
613618

614619
let current_target = if latest_release.build_status {
615620
if target.is_empty() {
@@ -1302,7 +1307,7 @@ mod tests {
13021307
// Same test with AJAX endpoint.
13031308
let response = env
13041309
.frontend()
1305-
.get("/-/menus/platforms/dummy/latest/dummy")
1310+
.get("/-/menus/platforms/dummy/latest/dummy/")
13061311
.send()?;
13071312
assert!(response.status().is_success());
13081313
check_links(response.text()?, true, true);
@@ -1316,7 +1321,7 @@ mod tests {
13161321
// Same test with AJAX endpoint.
13171322
let response = env
13181323
.frontend()
1319-
.get("/-/menus/platforms/dummy/0.4.0/x86_64-pc-windows-msvc/dummy")
1324+
.get("/-/menus/platforms/dummy/0.4.0/x86_64-pc-windows-msvc/dummy/")
13201325
.send()?;
13211326
assert!(response.status().is_success());
13221327
check_links(response.text()?, true, true);

src/web/csp.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ impl Csp {
7272
// Allow loading any font from the current origin.
7373
result.push_str("; font-src 'self'");
7474

75+
// Allow XHR.
76+
result.push_str("; connect-src 'self'");
77+
7578
// Only allow scripts with the random nonce attached to them.
7679
//
7780
// We can't just allow 'self' here, as users can upload arbitrary .js files as part of
@@ -190,7 +193,7 @@ mod tests {
190193
assert_eq!(
191194
Some(format!(
192195
"default-src 'none'; base-uri 'none'; img-src 'self' https:; \
193-
style-src 'self'; font-src 'self'; script-src 'nonce-{}'",
196+
style-src 'self'; font-src 'self'; connect-src 'self'; script-src 'nonce-{}'",
194197
csp.nonce()
195198
)),
196199
csp.render(ContentType::Html)

src/web/routes.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,19 @@ pub(super) fn build_axum_routes() -> AxumRouter {
237237
get_internal(super::source::source_browser_handler),
238238
)
239239
.route(
240-
"/-/menus/platforms/:name/:version/:target",
240+
"/-/menus/platforms/crate/:name/:version",
241+
get_internal(super::crate_details::get_all_platforms),
242+
)
243+
.route(
244+
"/-/menus/platforms/crate/:name/:version/:target",
245+
get_internal(super::crate_details::get_all_platforms),
246+
)
247+
.route(
248+
"/-/menus/platforms/crate/:name/:version/:target/*path",
249+
get_internal(super::crate_details::get_all_platforms),
250+
)
251+
.route(
252+
"/-/menus/platforms/:name/:version/",
241253
get_internal(super::crate_details::get_all_platforms),
242254
)
243255
.route(

0 commit comments

Comments
 (0)