繁体   English   中英

为什么500-内部服务器错误?

[英]why 500 - internal server error?

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();
});

这是后端代码:它是我的主路由器文件,所有相关路由都放置在该文件中

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

我收到内部服务器错误-500状态代码。 为什么这样?? 可能是什么原因?

我只需要使用body-parser包即可。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM