如何知道中间件被称为哪条路线?

时间:2016-12-27 11:06:07

标签: node.js express

我有中间件说:

with open(file_1, "r") as file1:
    with open(file_2, "r") as file2:
        diff = set(file1).difference(file2)

with open(file_o, "w") as file_out:
    for line in diff:
        file_out.write(line)
file_out.close()
if os.path.getsize(file_o) == 0:
    print "match"
else:
    print "does not match"

因此,在执行时我想检查哪个路由中间件正在被调用。

1 个答案:

答案 0 :(得分:1)

执行此操作的唯一方法是跟踪传入的Request object,并有选择地记录其中的部分内容,以了解当前正在执行的路由中正在使用哪些URL,查询字符串等。 / p>

例如,在您的中间件功能中,您可以编写如下内容:

var someMiddleware = function(req, res, next) {
  console.log('method:', req.method);
  console.log('originalUrl:', req.originalUrl);
};

HTTP方法和originalURL的组合将为您提供足够的信息,以便清楚地看到最终将要调用的路由。

相关问题