I’m just trying to test Serverless functions with React on Netlify but I’m not getting a response when I use Vite for React. Essentially what I did was:
- Created a new React application (npm create-react-app)
- Installed netlify-cli as a local dependacy
- Created a functions folder in the root directory with a javascript file called “data”:
exports.handler = async (event, context) => {
return {
statusCode: 200,
body: "Testing",
};
};
- Created the netlify.toml in root directory:
[build]
functions = "./functions"
- Ran npn run netlify, went to the URL of: http://localhost:8888/.netlify/functions/data and everything works!
However, if I use Vite to create my react app, I get this:
Request from ::1: GET /.netlify/functions/data
Response with status 404 in 1 ms.
I followed the exact same steps. The only difference is I used Vite instead of create-react-app. Does anyone know how to solve this problem?