I am currently working with an Express server that handles a login form page:
const app = express();
// part 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);
Everything is running smoothly so far.
Now, I have another controller that specifically deals with RAW DATA:
// part 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 can view the RAW DATA here
res.end('n');
}
Both sections function correctly on their own. However, when combined, the second section ceases to work properly.
Is there a way for me to specify that the req.pipe
should only be used for part B?