How to fix 405 error in node js and express js application when form action post method request

Scott Riches 20 Reputation points
2023-08-02T14:36:12.7033333+00:00

I have a node js with express js application making a post api request from index.html routing to the index.js where the api client is requested i.e. /send-sms. It works on local dev but gets a 405 error after deploying to azure app service. Not sure if Azure has a setting that needs to be configured. Any help appreciated.

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
827 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,496 questions
0 comments No comments
{count} votes

Accepted answer
  1. brtrach-MSFT 14,146 Reputation points Microsoft Employee
    2023-08-02T22:26:30.74+00:00

    @Scott Riches It seems like you are facing a 405 error when making a POST request to your Node.js and Express.js application after deploying it to Azure App Service. A 405 error indicates that the HTTP method used in the request is not allowed for the requested resource.

    There could be several reasons for this error, but one common reason is that the server is not configured to handle the HTTP method used in the request. In your case, it could be that the server is not configured to handle the POST method.

    To fix this issue, you can try the following steps:

    1. Check if your server-side code is correctly handling the POST request. Make sure that you have defined a POST route in your Express.js application and that it is correctly configured to handle the request.
    2. See if your client-side code is correctly sending the POST request. Make sure that the form action attribute is set to the correct URL and that the method attribute is set to "POST".
    3. Look at your Azure App Service is configured to allow POST requests. You can check this by going to the Azure portal, selecting your App Service, and then going to the "Configuration" section. Make sure that the "Allowed HTTP methods" setting includes "POST".
    4. Consider if there are any other settings in your Azure App Service that could be causing the issue. For example, if you are using authentication, make sure that it is correctly configured to allow POST requests.

    If you have any further questions or concerns, please let me know.


0 additional answers

Sort by: Most helpful