Node js Express how get raw data?

问题内容:

I have a express server that manages a login form page

const app = express();

// section A
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.urlencoded());

app.get('/login', userController.getLogin);
app.post('/login', userController.postLogin);

It run correctly.
Then i have another controller, that reads RAW DATA

// section B
const concat = require('concat-stream');
app.use(function(req, res, next) {
  req.pipe(concat(function(data: any) {
    req.body = data;
    next();
  }));
});

app.post('*', otherController.post);


export let post = (req: any, res: Response) => {
  console.log(req.body); //i see RAW DATA
  res.end('n');
}

It also works well

But if I join the 2 sections, the second section stops working

How can I say to use the req.pipe only for the section B?

问题评论:

原文地址:

https://stackoverflow.com/questions/47756730/node-js-express-how-get-raw-data

Add a Comment