#Netlify function works locally not in prod

1 messages · Page 1 of 1 (latest)

shy escarp
#
import { Handler } from '@netlify/functions';
import { getXataClient } from '../../api/xata';
export const handler: Handler = async (event, context) => {
  try {
    const xata = getXataClient();
    let allTodos = await xata.db['todo-list'].getAll();
    return {
      statusCode: 200,
      body: JSON.stringify(allTodos),
    };
  } catch (error) {
    console.error(error);
    return {
      statusCode: 500,
      body: JSON.stringify(error),
    };
  }
};
#

I am trying to create a todo app with vanilla js and xata with netlify serverless functions. when i try locally everything works fine but when deployed on netlify this function returns error.

quasi peak
#

Are you using environment variables locally?

coral anvil
#

And what is the error?

shy escarp
#

{}

shy escarp
coral anvil
#

Your getting a 500 error response from the server you'll probably need to look at the log on netlify. Also double check and make sure you've correctly configured your Env vars inside netlify

#

they will be under site settings inside the netlify console

shy escarp
shy escarp
#

found the problem i think i won't be able to solve this myself

#

and yeah i already tried installing node-fetch

#

doesn't work

coral anvil
#

is your repo public?

#

fetch should just work in netlify functions

shy escarp
#

just fixed that

#

i had to manually make sure that netlify was using nodejs v18 for lamda functions