Why doesn't the request object come to the server?
Request:

fetch('/api/teacher/createTest', { method: 'post', body: JSON.stringify(this.state) }) .then(() => { console.log('create test', JSON.stringify(this.state)); }); 

The generated query seems to look fine:

 create test {"id":1497705421652,"forGroups":[],"name":"","subscribers":[],"questionsCount":0,"questions":[]} 

Handler on server:

 app.post('/api/teacher/createTest', (req, res) => { console.log(req.body); }); 

This is what it displays (server console):

body-parser is connected:

 app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); 

Where is my mistake?

  • and in the browser console you see the transfer request? - Mikhail Vaysman
  • Heading application / json - and everything will be ok - Yuriy Po
  • @MikhailVaysman yes, everything is fine there - Fionor
  • @YuriyPo did not help, still nothing comes to the server - Fionor
  • What did not help? There headers: there must be an object - davidwalsh.name/fetch - Yuriy Po

0