表达/连接中间件,该中间件在响应发送到客户端后执行 [英] express/connect middleware which executes after the response is sent to the client

查看:73
本文介绍了表达/连接中间件,该中间件在响应发送到客户端后执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以编写一种中间件,该中间件在将响应发送给客户端之后或在将响应发送给客户端之前处理并调用请求之后执行?

Is it possible to write a middleware which executes after the response is sent to a client or after the request is processed and called just before sending the response to client?

推荐答案

pauljz给出了基本方法,但在此进行扩展的是中间件的示例

pauljz gave the basic method but to expand on that here is an example of middleware

module.exports = function() {
  return function(req, res, next) {
    req.on("end", function() {
      // some code to be executed after another middleware
      // does some stuff
    });
    next(); // move onto next middleware
  }
}

在您的主应用中

expressApp.use(require("./doneMiddleware"));
expressApp.use(express.logger());
expressApp.use(express.static.....

这篇关于表达/连接中间件,该中间件在响应发送到客户端后执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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