配置中间件-Node Express



我有一个中间的WARE函数自定义者,应在所有ProcessPayments请求之前运行。因此,我配置了如下路由。但是,当我运行服务器时,中间件功能一直运行。我应该如何重新配置以下代码

'use strict';
var payments = require('../controllers/payments.server.controller');
module.exports = function(app) {
  app.use(payments.customerExists); // Middleware - 
  app.route('/api/process/payment/')
    .get(payments.processPayments);
};

app.use(payments.customerExists)当应用启动

时将通过默认运行

如果您没有更多的/api/process/payment/路线,那么上面的解决方案非常适合您在获得请求

时做
'use strict';
var payments = require('../controllers/payments.server.controller');
module.exports = function(app) {
    app.get('/api/process/payment/', payments.customerExists, 
    payments.processPayments); 
};

最新更新