0

I am getting 405 method not allowed. I am using axios.post for login. The form is taking input username and password and post to get authenticate. But POST method not allowed at heroku error in console.

Please help me to let me know how to enable POST method on heroku. or any solution.

Thanks in advanceenter image description here

1 Answers1

0

This is an axios post example:

axios.post("test/test", {userName:'..', password:'..'}).then((result) => onSuccess(result.data), (error) => onError(error));

If you are using spring-boot with Java you probably have a CORS problem. Try to put in your endpoint:

@CrossOrigin(origins = {"http://localhost:3000", "url2", "url3})

Replace "http://localhost:3000" with your localhost url if you need it. This is an example:

@CrossOrigin(origins = {"http://localhost:3000", "url2", "url3})
@RequestMapping(value = "/test", method = RequestMethod.POST)
ResponseEntity<HttpStatus> testLoginUser(@RequestBody DTO testDto) throws TestException {

     //Do Something..
}

I don't know how the server is implemented, so: check if you have a CrossOrigin problem or if you have a security problem with your endpoints.

Paolo Dell'Aguzzo
  • 1,431
  • 11
  • 14
  • I am using MERN stack on heroku – Gurman P. Singh Jun 21 '18 at 15:42
  • Check if you have problems on ports (like https://stackoverflow.com/questions/50591374/mern-stack-express-and-react-on-same-port). At the end: ensure your server.js is running correctly and ensure that you don't have cross origin problems (https://stackoverflow.com/questions/18310394/no-access-control-allow-origin-node-apache-port-issue) Ensure you have done all the necessary steps: https://coursework.vschool.io/deploying-mern-with-heroku/ Another good link: https://hashnode.com/post/react-tutorial-using-mern-stack-ciiyus9m700qqge53mer0isxz – Paolo Dell'Aguzzo Jun 22 '18 at 06:46
  • App is on heroku server. I have contacted support and they replied: "The create-react-app-buildpack uses the heroku/static buildpack which in turn uses a nginx web server. Unfortunately nginx does not allow POST calls from static pages. You will need to make a GET request here." – Gurman P. Singh Jun 22 '18 at 08:21
  • So, I think that you cannot edit the nginx.conf file because only Heroku can edit it. Check if you can do something like this: https://m.alphasights.com/using-nginx-on-heroku-to-serve-single-page-apps-and-avoid-cors-5d013b171a45 – Paolo Dell'Aguzzo Jun 22 '18 at 09:54