POST request not working in NodeJs app in Cpanel

Viewed 389

I was creating a Node App using Express JS. There's a route which accepts a POST Request. The app works fine on localhost, but when I host on Cpanel Shared Hosting, I get the following error for POST request. GET works fine. Can anyone please help or guide where I went wrong?

<html lang="en">

<head>
   <meta charset="utf-8">
   <title>Error</title>
</head>

<body>
   <pre>Cannot GET /v1/email</pre>
</body>

</html>

My Express JS code

var app = express();
var em =require('./mailjet')
var bodyParser = require('body-parser');
app.use(bodyParser.json())

app.get('/v1', function (req, res) {
   return res.json('Hello World');
})

app.post('/v1/email', function (req, res) {
    let {name, email, message}=req.body
    if (!name || !email || !message){
        return res.status(400).send({
            'Message':'Bad Request'
        })
    }
    em.request(name, email, message)
   return res.status(200).send({
       'Message':'Email Sent'
   });
 })

 app.listen()
0 Answers
Related