I've been trying to set up a serverless function for sending emails in my Gatsby website. The function is being hosted, but whenever I try to get it, it tells me that it doesn't exist.
My fetch:
const body = {
name,
email,
phone,
message,
};
fetch(`http://localhost:8000/.netlify/functions/sendMail`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(body),
})
.then((res) => console.log(res.data))
.catch((err) => console.error(err));
Middleware in gatsby-config.js
:
developMiddleware: (app) => {
app.use(
"/.netlify/functions/",
createProxyMiddleware({
target: "http://localhost:8000",
pathRewrite: {
"/.netlify/functions/": "",
},
})
);
},
Function path:
- root
- functions
- sendMail
- node_modules
- package.json
- sendMail.js
- yarn.lock
- sendMail
- functions
I think it has something to do with the url I am getting it with in my fetch()
function.