PLEASE help us help you by writing a good post!
I am using netlify function to create a proxy for API endpoint. For some reason, I am getting event.queryStringParameters.seconds
even though I ma passing parameter form my frontend
Here is the code
exports.handler = async (event, context) => {
const seconds = event.queryStringParameters.seconds;
console.log("SECONDS : ", event.queryStringParameters.seconds);
// whole event.queryStringParameters object is null
const targerUrl = `https://blockchain.info/blocks/${seconds}000?format=json`;
try {
const response = await fetch(targerUrl);
return {
statuCode: 200,
// .data
body: JSON.stringify(response),
};
} catch (error) {
return {
statusCode: 500,
body: JSON.stringify(error),
};
}
};
React code
useEffect(() => {
const getData = () => {
const url2 = `/.netlify/functions/getData?seconds=${7000000}`;
console.log("URL2: ", url2);
// "/blocks/1483228800000?format=json"
fetch(url2)
.then((res) => res.json())
.then((data) => setBlockData(data));
};
if (value !== null) {
getData();
}
}, []);
I am testing this in my local environment by using the netlify-lambda package