Last active
June 11, 2018 18:20
-
-
Save j4p3/91e2b5f616004fd702608566023686f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
exports.handler = (event, context, callback) => { | |
// Extract request from the CloudFront event that is sent to Lambda@Edge | |
var request = event.Records[0].cf.request; | |
// Match any '/' that occurs at the end of a URI. | |
// Replace it with /index.html. | |
if (request.uri.match(/^((?!\.(css|js|html|xml|txt|ico|jpg|png|gif|json|pdf)$).)*$/)) { | |
request.uri = request.uri.replace(/\/$/, '/index.html'); | |
} | |
// Return request with modified URI to CloudFront | |
return callback(null, request); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment