防爆preSS途径处理/ req.body对部分航线的空 [英] Express route handling / req.body empty on some routes

查看:111
本文介绍了防爆preSS途径处理/ req.body对部分航线的空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两条路线。每个请求之前,应该有火法:

I have two routes. Before each request, there should fire a method:

app.all('*',function(req,res,next){
    console.dir(req.body);
    // Some more stuff
});

我做一个 POST 打电话给我的第一条路线:

I make a POST call to my first route:

$ http.post('/用户/登录',{
              别名:$ scope.alias,
              密码:$ scope.password
          });

$http.post('/users/login',{ alias: $scope.alias, password: $scope.password });

一切都工作得很好,前preSS日志凭据到控制台上。

Everything works just fine, Express logs to the credentials to the console.

我把另一条路线:

$ http.post('/货运/删除',{
              别名:'11',
              密码:'22'
          })

$http.post('/shipments/delete',{ alias: '11', password: '22' })

防爆preSS记录一个空的对象。

Express logs an empty Object.

WTH发生在这里?

推荐答案

也许不同的路由匹配POST到 /用户/登录。防爆preSS路由大约是匹配的请求路径处理函数。你必须张贴所有相关航线路径和处理功能,为我们向你展示你的错误,如果你不相信你可以决定哪些是相关的,张贴他们。但实际上你可能不希望使用 app.all('*'以往任何时候都了解中间件: app.use(,而不是因为这两个工作略有不同,中间件是一般更正确的/有用的。

Probably a DIFFERENT route is matching the POST to /users/login. Express routing is about matching request paths to handler functions. You have to post all of the relevant route paths and handler functions for us to show you your mistake, and if you're not confident you can determine which are relevant, post them ALL. But really you probably don't want to be using app.all('*' ever. Learn about middleware: app.use( instead because these two work slightly differently, with middleware being generally more correct/useful.

这篇关于防爆preSS途径处理/ req.body对部分航线的空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆