Last active
February 16, 2022 16:06
-
-
Save afro-coder/53e1fc9729ccbae5d3be9ddd160259e6 to your computer and use it in GitHub Desktop.
Cloudfront function to rewrite and redirect to a different location
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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