Skip to content

Instantly share code, notes, and snippets.

@furkan3ayraktar
Created March 29, 2018 16:36
Show Gist options
  • Save furkan3ayraktar/1c60235c1f50f8684a21370bff78fed5 to your computer and use it in GitHub Desktop.
Save furkan3ayraktar/1c60235c1f50f8684a21370bff78fed5 to your computer and use it in GitHub Desktop.
Detecting relevant paths in the request.
const path = require('path');
exports.handler = (event, context, callback) => {
const { request, config } = event.Records[0].cf;
let originalUri = request.uri;
const parsedPath = path.parse(originalUri);
if (parsedPath.ext === '') {
// Every request that does not have an extension should be a route in our
// SPA. We can fetch index.html here and add proper metadata. All other
// requests with proper extensions should be redirected to actual resource
// in S3.
} else {
return callback(null, request); // Do not modify request.
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment