Skip to content

Instantly share code, notes, and snippets.

@j4p3
Last active June 11, 2018 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j4p3/91e2b5f616004fd702608566023686f6 to your computer and use it in GitHub Desktop.
Save j4p3/91e2b5f616004fd702608566023686f6 to your computer and use it in GitHub Desktop.
'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