Hi There,
I am struggling a bit with functions. My function at ‘/api/getSections’ looks like this:
exports.handler = async function(event, context) {
let fileData = await this.getAllMetaData();
return {
statusCode: 200,
body: JSON.stringify(fileData)
};
}
When running netlify dev, netlify:functions invoke I get the response I need but when moving into the browser I see SyntaxError: Unexpected token < in JSON at position 0.
My fetch request looks like:
const getSections = () => {
fetch('/api/getSections')
.then(response => response.json())
.then(data => console.log(data));
If I log out the response I see:
I have been through this topic in detail: Netlify Dev Functions Locally troubleshooting - but it hasn’t helped. I am hoping there is something small I am missing. I haven’t been able to find any clues as all the documentation seems to indicate this should work without configuration. I am using next ^10.0.1 and static export. If I try this function on a branch deploy I get the same result.
Any guidance on getting this to work in any environment other than the CLI in order to troubleshoot from there would be greatly appreciated.
Warm Regards,
Nick