Skip to content

Commit

Permalink
crates-io/cloudfront-functions: Add support for download URLs without…
Browse files Browse the repository at this point in the history
… placeholders
  • Loading branch information
Turbo87 committed Dec 7, 2023
1 parent ba0cb0a commit 2c6252e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions terragrunt/modules/crates-io/cloudfront-functions/static-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,15 @@ function handler(event) {
request.uri = request.uri.replace("+", "%2B");
}

// cargo versions before 1.24 don't support placeholders in the `dl` field
// of the index, so we need to rewrite the download URL to point to the
// crate file instead.
var match = request.uri.match(/^\/crates\/([^\/]+)\/([^\/]+)\/download$/);
if (match) {
var crate = match[1];
var version = match[2];
request.uri = `/crates/${crate}/${crate}-${version}.crate`;
}

return request;
}

0 comments on commit 2c6252e

Please sign in to comment.