//问题如下,当app.all在app.configure之前调用的话,后续的get 或者post 的req.body 都为undefine
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin,X-Requested-With,Content-Type,Accept,params");
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By",' 3.2.1')
res.header("Content-Type", "application/json;charset=utf-8");
next();
});
app.configure(function(){
app.use(express.methodOverride());=========================================================================================
正确的顺序应该是这样
app.configure(function(){
app.use(express.methodOverride());
app.use(express.bodyParser());//{ keepExtensions: true, uploadDir: './public/image' }
app.use(express.cookieParser());
app.use(everyauth.middleware());
app.use(app.router);
app.set('view engine', 'jade');
app.set('views', __dirname + '/public');
app.set('view options', {layout: false});
app.set('basepath',__dirname + '/public');
});
app.configure('development', function(){
app.use(express.static(__dirname + '/public'));
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
var oneYear = 31557600000;
app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
app.use(express.errorHandler());
});
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin,X-Requested-With,Content-Type,Accept,params");
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By",' 3.2.1')
res.header("Content-Type", "application/json;charset=utf-8");
next();
});
//全套creator html5 + nodejs pomelo express 实践开发,喜欢交流的加扣扣群427719099,你喜欢问我就喜欢答,欢迎入坑