Reputation: 2136
I've configured some rules with custom responses in AWS WAF to prevent some users from accessing my website based on their geographical location. I can see that these rules are working as intended because I am able to see the custom response status (406
) and response header (custom-header
) in the network tab, but I am struggling to find a way for my web client to access any of these values within JS code (using fetch or axios). While using the fetch
API, I receive the following error without any response
value: TypeError: Failed to fetch
.
I've tried using some of the recommended approaches like utilizing a 302
status code + Location
header, but these only work for navigation based GET requests, not ajax ones.
Is there any way to do this other than using some proxy web server between the client and cloudfront?
fetch(URL, {
headers: {
Accept: "application/json, text/plain, */*",
...
},
// mode: "no-cors", // Results in opaque response
})
.then((res) => {
console.log("$$$ - res: ", res);
})
.catch((err) => {
console.log("$$$ - err: ", err); // TypeError: Failed to fetch
});
Upvotes: 0
Views: 85
Reputation: 19
Here are some tips that can help you fix this:
I think it will be more helpful if you can share more of WAF configuration.
Upvotes: 0