Solving a 405 error that appears in my Azure Static Web App but not on my local machine

Kyle Johnson 0 Reputation points
2025-07-04T00:23:38.53+00:00

I've deployed a personal website as an Azure static web app here: https://salmon-pond-098a94d10.1.azurestaticapps.net/

On the "Contact" page, I've implemented a simple contact form that takes the input data and sends an axios post request like so:

const result = await axios.post('/api/sendEmail', {
      name: name,
      email: email,
      message: message
    }).catch(err => {
      console.log(err);
    });

I can confirm that the catch statement gets triggered, because on submitting the form, the console shows the following 405 error:

error

Now, this post request hits a simple express.js server located elsewhere in my codebase, the relevant code is as follows:

const dotenv=require('dotenv');
dotenv.config();
const express = require('express');
const path = require('path');
var bodyParser = require('body-parser');
const { Resend } = require("resend");

const PORT = process.env.PORT || 8080;
const app = express();
const resend = new Resend(process.env.RESEND_API_KEY);

app.use(express.static(path.join(__dirname, '..', 'public')));
app.use(bodyParser());

app.get('/', (req, res) => {
  res.send('Hello from the server!');
});

app.post('/api/sendEmail', async (req, res) => {
  const { data, error } = await resend.emails.send({
    from: "******@adomainIown.com",
    to: ["******@myemail.com"],
    subject: `Message from ${req.body.name} through your personal website!`,
    html: `From ${req.body.email}: ${req.body.message}`
  });

  if (error) {
    return res.status(400).json({ error });
  }

  res.status(200).json({ data });
});

All of this goes smoothly and the email is successfully sent when I'm running this on my local machine at localhost:3000. However, the 405 error crops up whenever I try doing this on the live static web app, which is strange to me because nowhere in my code do I ever explicitly instruct my application to send a 405 error. So, where is it coming from? Why is the request not allowed? Is there some settings in Azure that I have to configure? I've already entered the environment variables, though I think having no API key or having an incorrect API key would produce a different error.

Thanks in advance!

Azure App Configuration
Azure App Configuration
An Azure service that provides hosted, universal storage for Azure app configurations.
277 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.