Hi all, can someone please help me make sense of this sudden error?
Failed to load resource: the server responded with a status of 404 ()
All of a sudden, all api calls are returning a 404
error in production (Netlify), but when run locally, everything works as expected.
While debugging this issue, I cleared the cache and forced a redeploy of the app and my staging app is finally working again, but not the main one. Both sites are identical clones. The staging.mysite.com
runs from my Github dev
repo, while mysite.com
runs from the main
repo.
Hereβs a code snippet for example:
// server/api/send.post.ts
export default defineEventHandler(async (event) => {
client.setApiKey(SENDGRID_API_KEY);
if (event.node.req.method !== "POST") return { error: "Method not allowed" };
const payload = (await readBody(event)) as client.MailDataRequired;
try {
const response = await client.send(payload);
consola.success("π Message sent");
return response[0].statusCode;
} catch (error) {
// ...
consola.error("Send failed", error);
}
});
Iβm calling this from the frontend like this:
async function submit() {
const msg = {
to: "info@email.com",
from: "noreply@email.com",
subject: "You have a message",
template_id: "xxx",
dynamic_template_data: {
message: `${form.firstname} would like to connect with you.`,
...form
}
};
try {
await useFetch("/api/send", {
method: "POST",
body: msg
});
} catch (e) {
console.log("send failed", e)
}
}
I should note that this issue happened out the blue about a week ago, though no breaking changes were made to the codebase. Just an environment variable was updated.
Thanks in advance.