Ashish
Ashish

Reputation: 309

How to use express middleware in SailsJS?

I want to use one of the ExpressJS middleware in SailsJS application. Its the "express-limiter" module(which is a express middleware) for rate limiting an api using IP address. Normally in express we do:

app.use(limiter({ some parameters }))

How to I use this middleware or any other express middleware in SailsJS application? Appreciate your help.

Upvotes: 4

Views: 1095

Answers (2)

Simone Pontiggia
Simone Pontiggia

Reputation: 204

  1. install the middleware npm install --save express-limiter

  2. change the config/http.js file adding the express-limiter

    middleware: {
       order: [
          'express-limiter-key'
       ],
       'express-limiter-key' = require('express-limiter')
    }
    

the var limiter = require('limiter') won't work since > middleware.orderis simply a lookup, and will search only keywords in middleware object.

Upvotes: 2

Marek Urbanowicz
Marek Urbanowicz

Reputation: 13644

  1. Install your middle ware by npm install --save yourMiddleware
  2. Go to sails.config.http.middleware
  3. on top place `var limiter = require('limiter')
  4. Put limiter in the order, I suppose close to the top.

Upvotes: 1

Related Questions