Reputation: 15656
Without router middleware, once the server side receive the post data, it could log it normally:
var express = require('express');
var app = express.createServer();
app.configure(function () {
app.use(express.static(__dirname + '/static'));
// app.use(app.router);
app.use(express.bodyParser());
})
app.get('/', function(req, res){
res.send('Hello World');
});
app.post('/', function(req, res){
console.log('body:', req.body);
res.send(req.body);
});
app.listen(8000);
But once I use the router
middleware, the log result is undefined
and response nothing
Why? How can I solve this problem?
Upvotes: 2
Views: 1065
Reputation: 10864
The problem is the order you called router
bodyParser must be called before router
app.configure(function () {
app.use(express.static(__dirname + '/static'));
app.use(express.bodyParser());
app.use(app.router);
});
Upvotes: 2