req.body在快速POST中是空的

时间:2018-04-06 11:05:29

标签: node.js angular express

当我尝试从我的角度服务中恢复数据时,req.body对象显示为空。即使数据在我的角度http请求中传输得很好。

  public reset(email: string): Observable<Boolean> {
    return this.http.post<Boolean>('/api/reset/reset', email); // email exists
  }

我的快递路线:

router.post('/reset', (req, res) => {
    console.log(req.body.email); // undefined
    async.waterfall([
        function (done) {
            //code
        },
        function (token, done) {
           //code
        },
        function (token, user, done) { 
           //code
        }
});

这是我的app.js,但我已经检查了bodyParser()的存在

const express = require('express');
const path = require('path');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const app = express();
const index = require('./routes/index');
const passport = require('passport');
const session = require('express-session');
const cors = require('cors');

app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, '../public')));
app.use(passport.initialize());
app.use(passport.session());


mongoose.connect('MYCONNECTIONSTRING', {
    keepAlive: true,
    reconnectTries: Number.MAX_VALUE
  }, function (error) {
    if (error) {
      console.log(error);
    } else {
      console.log('Connexion opened to mongodb!');
    }
});

app.use(index);

app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname, '../public/index.html'));
});

module.exports = app;

这个错误已经在堆栈溢出时得到了解答,但我找到的所有答案都没有解决我的问题。

0 个答案:

没有答案