const form = document.getElementById('vote-form')
form.addEventListener('submit',e => {
let choice = document.querySelector('input[name=os]:checked').value;
let data = {os: choice};
fetch("http://localhost:3000/poll",{ // *** getting error here
method:'post',
body:JSON.stringify(data),
headers: new Headers({
'Content-Type':'application/json'
})
}).then(res => res.json()).then((data) => {console.log(data)}).catch(err => console.log(err))
e.preventDefault();
});
Here`s the backend code: Its my main router file, where all related routes are placed
const express = require('express')
const router = express.Router()
const Pusher = require('pusher')
let pusher=new Pusher({
appId:'*******',
key:'*****',
secret:'******',
cluster:'*****',
encrypted:true
});
router.get('/',(req,res) => { //it actually means /poll (as mentioned in app.js)
res.send('polling starts');
})
router.post('/',(req,res)=>{
pusher.trigger('os-poll','os-vote',{
points: 1,
os: req.body.os
});
res.json({success:true,message:"thanks for voting"})
});
module.exports=router
I am getting Internal Server Error - 500 Status code. Why so?? What could be the possible reason?