How to use custom route middleware with Sails.js? (ExpressJS)

后端 未结 3 1671
独厮守ぢ
独厮守ぢ 2021-01-12 01:15

I\'ve just unpacked a fresh copy of the Node framework Sails.js. It is built on Express 3. In the /config/routes.js file is this comment:

/**
 * (1) Core m         


        
3条回答
  •  一向
    一向 (楼主)
    2021-01-12 01:35

    To add compress middleware of express, I find this thread and

    sails-middleware-example-issue are very usefull.

    1. install express local: npm install express
    2. load express: var exp = require('express')
    3. add customMiddleware in $app_dir/config/local.js
    express: {
        customMiddleware: function (app) {
          console.log("config of Middleware is called");
          app.use(exp.logger());
          app.use(exp.compress());
          app.use(function (req, res, next) {
            console.log("installed customMiddleware is used");
            next();
          })
        }
      }
    

提交回复
热议问题