Skip to content

Commit c3d8050

Browse files
Allow platforms async load to work on docs.rs crates pages
1 parent f3d8e3e commit c3d8050

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/web/crate_details.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ pub(crate) async fn get_all_platforms(
496496
Extension(pool): Extension<Pool>,
497497
uri: Uri,
498498
) -> AxumResult<AxumResponse> {
499-
let is_crate_root = uri.path().starts_with("/crate/");
499+
let is_crate_root = uri.path().starts_with("/-/menus/platforms/crate/");
500500
let req_path: String = params.path.unwrap_or_default();
501501
let req_path: Vec<&str> = req_path.split('/').collect();
502502

@@ -601,6 +601,11 @@ pub(crate) async fn get_all_platforms(
601601

602602
(target, inner_path.join("/"))
603603
};
604+
let inner_path = if inner_path.is_empty() {
605+
format!("{name}/index.html")
606+
} else {
607+
format!("{name}/{inner_path}")
608+
};
604609

605610
let current_target = if latest_release.build_status {
606611
if target.is_empty() {
@@ -1293,7 +1298,7 @@ mod tests {
12931298
// Same test with AJAX endpoint.
12941299
let response = env
12951300
.frontend()
1296-
.get("/-/menus/platforms/dummy/latest/dummy")
1301+
.get("/-/menus/platforms/dummy/latest/dummy/")
12971302
.send()?;
12981303
assert!(response.status().is_success());
12991304
check_links(response.text()?, true, true);
@@ -1307,7 +1312,7 @@ mod tests {
13071312
// Same test with AJAX endpoint.
13081313
let response = env
13091314
.frontend()
1310-
.get("/-/menus/platforms/dummy/0.4.0/x86_64-pc-windows-msvc/dummy")
1315+
.get("/-/menus/platforms/dummy/0.4.0/x86_64-pc-windows-msvc/dummy/")
13111316
.send()?;
13121317
assert!(response.status().is_success());
13131318
check_links(response.text()?, true, true);

src/web/csp.rs

+4-1
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

+13-1
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)