Hick
Hick

Reputation: 36374

NodeJs not taking post requests

This is a simple app that takes a post request and saves mail id in it.

app.get('/', function (req, res) {
  res.render('index',
  { title : 'Home' }
  )
});

app.post(
        '/mail/',
        function(req,res){
            Mail.addMail(

                req.body.mailid,
                function(err,mail){
                    if((mail) &&(!err)){
                        res.send(200);
                    }
                    else{
                        res.send(401,err);
                    }
                }

                );
        }
        );


app.listen(3000);
console.log('Listening on port 3000');

When I try to ping it via python:

r = requests.post('http://127.0.0.1:3000/mail/')

The server doesnt' respond at all. Not even a post request gets registered. The get request works fine, though. Where am I going wrong?

Upvotes: 0

Views: 72

Answers (1)

phonicx
phonicx

Reputation: 479

I think that node.js routes should be defined without the trailing slash - you could try that.

Apart from that it looks fine to me..

Upvotes: 1

Related Questions