async function handler(event) {
const request = event.request;
const uri = request.uri;
console.log("uri before: " + uri);
// note: this fixes the problem with '/latest' returning broken page with invalid links
// it doesn't help with URLs like '/versions/8.8.0' (missing trailing slash)
// but usage of those is rare
if (uri.endsWith('/latest')) {
return { statusCode: 301, headers: { "location": { "value": "/latest/" } }};
}
// Check whether the URI is missing a file name.
if (uri.endsWith('/')) {
request.uri += 'index.html';
}
// Check whether the URI is missing a file extension.
else if (!uri.includes('.')) {
request.uri += '/index.html';
}
console.log("uri after: " + request.uri);
return request;
}