Cant retrieve headers from network source type "Fetch/Redirect"

17 Views Asked by At

So I'm working on a flask app that runs a javascript function upon hitting a button. This calls a fetch request to an app route, that then calls a cloudfront function. This calculates some data, then returns a custom header with the calculation result. The issue is I'm not able to use the fetch request to actually retrieve the data, as it's returning headers from another response and I'm not sure why. This is my javascript code im using:

function fibonacci() {
                        var n = document.getElementById('fibCFInput').value;
                        console.log("testing.." + n)


                        console.log("cloudfront test...")
                        fetch("https://<cloud url>/fibonacci/" + n)
                                .then(response => {

                                response.headers.forEach((value, name) => {
                                console.log(`${name}: ${value}`);
                                });

                                const fibval = response.headers.get("fibval");
                                console.log(`fibval value: ${fibval}`);
                        })
                        .catch(err => {
                        console.error('Error fetching data:', err);
                        });

                        console.log("fetch break")

                        console.log("fibonacci test")
                        fetch('/fibonacci/' + n, {redirect: "follow"})
                        .then(response => {
                                response.headers.forEach((value,name)=>{
                                console.log(`${name}: ${value}`);
                                });
                                const fibval = response.headers.get("Fibval");
                                console.log(fibval)
                        })
                        .catch(err => {
                        console.error('Error fetching data:', err);
                        });
                        }

I have two test cases to try requesting straight from cloudfront, and another going through the app route. interestingly enough, the cloudfront fetch returns no headers at all.

I've tried adding different CORS settings as I thought that might be the issue, but with CORS fully enabled on the domain and the cloudfront function returning Access-control-allow-origin: * (for testing purposes), I'm not sure what may be the issue other than the redirect mechanism.

0

There are 0 best solutions below