Skip to content

Commit

Permalink
fix: redirect static-router/doc/master to stable docs (#568) (#571)
Browse files Browse the repository at this point in the history
Co-authored-by: Marco Ieni <[email protected]>
  • Loading branch information
softmoth and MarcoIeni authored Dec 2, 2024
1 parent f449af2 commit 90a4512
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
25 changes: 25 additions & 0 deletions terragrunt/modules/release-distribution/fastly-static.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ resource "fastly_service_vcl" "static" {
VCL
}

snippet {
name = "detect doc-master requests"
type = "recv"
content = <<-VCL
if (req.url ~ "^\/doc\/master\/") {
error 619 "redirect";
}
VCL
}

snippet {
name = "enable segmented caching"
type = "recv"
Expand Down Expand Up @@ -115,6 +125,21 @@ resource "fastly_service_vcl" "static" {
VCL
}

snippet {
# This was an abandoned copy of Rust 1.17.0-era docs; redirect to current docs
name = "redirect doc-master to stable"
type = "error"
content = <<-VCL
if (obj.status == 619 && obj.response == "redirect") {
set obj.status = 301;
set obj.response = "Moved permanently";
set obj.http.Location = regsub(req.url, "^\/doc\/master", "https://doc.rust-lang.org/stable");
return (deliver);
}
VCL
}

logging_datadog {
name = "datadog"
token = data.aws_ssm_parameter.datadog_api_key.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,16 @@ echo " curl https://sh.rustup.rs -sSf | sh"
return redirect('https://sh.rustup.rs', body, callback);
}

// Links to `/doc/master/*` are probably from old external sources, so send
// them back through the doc site to take advantage of any helpful error
// handling that may be defined there
if (request.uri.startsWith('/doc/master')) {
// The slice method is used to remove the '/doc/master' prefix from the
// URI. 11 is the length of '/doc/master'.
const newUri = 'https://doc.rust-lang.org/stable' + request.uri.slice(11);
const body = "The documentation now lives under doc.rust-lang.org";
return redirect(newUri, body, callback);
}

callback(null, request);
};

0 comments on commit 90a4512

Please sign in to comment.