Skip to content

Instantly share code, notes, and snippets.

@afro-coder
Last active February 16, 2022 16:06
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 afro-coder/53e1fc9729ccbae5d3be9ddd160259e6 to your computer and use it in GitHub Desktop.
Save afro-coder/53e1fc9729ccbae5d3be9ddd160259e6 to your computer and use it in GitHub Desktop.
Cloudfront function to rewrite and redirect to a different location
function handler(event) {
var request = event.request;
var uri = request.uri;
if (uri.startsWith('/api')) {
uri=uri.replace('/api/','')
var newurl = `https://backend-url/${uri}`
var response = {
// The status code is important.
statusCode: 302,
statusDescription: 'OK',
headers:
{ "location": { "value": newurl}
}
}
return response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment