Open matiasgarciaisaia opened 2 weeks ago
I don't think this is solvable with the S3 bucket redirection rules - we would need to be able to say that the rules we have don't apply to /api/1
and /api/0
paths, so S3 serves the error document (which is set to be the /api/1.12.1/404.html
page).
I'll check if this is doable with a lambda function - and if its cost fits within our AWS budget.
I think we can replace the patchwork of S3 rules for only one rule redirecting /api/latest
-> /api/${current_version}
if we add this javascript snippet to the 404.html page:
<script type="text/javascript">
if(!document.location.pathname.match(/^\/api\/[0-9]/)) {
const new_path = document.location.pathname.replace(/^\/api\//, "/api/latest/")
document.location.pathname = new_path
}
</script>
That way, visiting /api/String.html
in a browser will redirect users to /api/latest/String.html
, which gives a 302 Temporary redirect to /api/${current_version}/String.html
- a 200 OK. But visiting /api/not-exists
ends up at /api/${current_version}/not-exists
, which returns a 404 Not Found
.
This only works on browsers with JavaScript enabled. Other user agents will miss the /api/String.html
-> /api/latest/String.html
redirection.
What do you think?
I'm strongly opposed to use client-side JavaScript to overpaint technical limitations of the web server. Implementing redirection is a responsibility of the HTTP server, not the client.
Due to the redirect rules we have in place to default API Docs to the latest released version (see #312 for some context), we never send a 404 HTTP status to clients when they request non existent pages in the
/api/
path.We should improve the routes handling so we eventually respond with 404 Not found HTTP Status (even if that's after some redirects).