function handler(event) {
    var request = event.request;
    var uri = request.uri;

    // Check whether the URI is missing a file extension
    if (!uri.includes('.')) {
        // Check if URI ends with /
        if (uri.endsWith('/')) {
            request.uri += 'index.html';
        } else {
            // For Next.js static export, try .html first
            // CloudFront will handle 404s via custom error response
            request.uri += '.html';
        }
    }

    return request;
}
