0

I have an issue with a simple app nodeJS and jQuery app I have deployed to Heroku. I am using a post request which functions on my localhost but when deployed to heroku returns the following error:

Cannot GET /api/friends

This request is made via a front end html form:

'<a href="/api/friends" method='post'><button type="button" class="btn 
btn-success" id="submit">Submit</button></a>'

on the server it is processed with this:

    app.post('/api/friends', function(req, res) {

        var user = new User(req.body.name, req.body.species, req.body.scores);

        user.match();

        res.json(user.bestie);
});

Any ideas why this might be giving me the above error message in Heroku? I have looked through stackoverflow and can only seem to find similar issues in PHP.

Thanks Mike

Dacre Denny
  • 29,664
  • 5
  • 45
  • 65
  • 1
    It looks like you're trying to make a POST request from an A tag. (https://stackoverflow.com/questions/6180256/post-from-an-a-tag) You should probably be using a form instead. (https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Sending_and_retrieving_form_data) – GMK Jul 23 '18 at 23:30
  • GMK - thank you. I went off and was researching express processing of get/post and whether certain responses res.json() res.send() are processed as gets/posts. I missed this simple underlying error. – Mike Fields Jul 24 '18 at 18:10

0 Answers0