В node.js express не передаются POST-параметры
В node.js express не передаются POST-параметры из фронта, т.е. если смотреть поступивший запрос, то поле request.body == {}
Конфигурация express:
var express = require('express');
var cors = require("cors");
var newTask = require('./routes/new_task');
var app = express();
app.use(express.json() );
app.use(express.urlencoded({
extended: true
}));
app.use('/new-task', newTask);
app.use(cors({
origin: 'http://localhost:*',
credentials: true}));
Запрос отправляю так:
var myHeaders = new Headers();
myHeaders.append('Content-Type', 'application/json; charset=utf-8');
fetch(PLACE_TASK_ENDPOINT, {
method: 'POST',
headers: myHeaders,
mode: 'no-cors',
cache: 'no-cache',
body: JSON.stringify({a: 1})
});
Если сделать запрос через curl в командной строке, то параметры в express видно.