4 ms·
I've just tried it. The following function works exactly as-is when the function is configured as Viewer request. I changed it to append some text to URL. See:
by CSDude 5y ago
I've just tried it. The following function works exactly as-is when the function is configured as Viewer request. I changed it to append some text to URL.
See: https://github.com/aws-samples/amazon-cloudfront-functions/blob/main/url-rewrite-single-page-apps/index.js https://github.com/aws-samples/amazon-cloudfront-functions/b...
- herpderperator 5y agoThat MODIFIES a viewer request, resulting in a viewer redirect. We want to keep the viewer request the same, i.e. with /api, and strip it only from the backend origin request. The viewer request is the one you make from the client, with /api. The origin request is the one CloudFront sends to your backend, which, without using Lambda@Edge via the origin request, will get sent as-is with the /api prefix. You have to strip it from the origin request. If you strip /api from the viewer request, your `domain.com/api/users` request becomes a redirect to `domain.com/users` which results in a call to your frontend instead of your backend. The example you referenced solves a completely different issue, not the one we are talking about.