Skip to content

Instantly share code, notes, and snippets.

@j4p3

j4p3/uriSwap.js

Last active Jun 11, 2018
Embed
What would you like to do?
'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
You can’t perform that action at this time.