Skip to content

Instantly share code, notes, and snippets.

@pesterhazy
Created September 26, 2018 14:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pesterhazy/05639a992fdaa965464e7ce680832712 to your computer and use it in GitHub Desktop.
Save pesterhazy/05639a992fdaa965464e7ce680832712 to your computer and use it in GitHub Desktop.
Lambda@Edge trigger: simple URL rewriting
"use strict";
// Lambda@Edge trigger to serve index.html when the
// user requests /app/*; use in Cloudfront as a viewer-request
// event
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
if (/^\/app($|\/)/.test(request.uri) || request.uri == "/") {
request.uri = "index.html";
}
callback(null, request);
};
@cdechery
Copy link

cdechery commented Mar 2, 2020

Would a code like this one work to rewrite a URL that is served by another domain?

@pesterhazy
Copy link
Author

pesterhazy commented Mar 4, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment