Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 705
Ashish Avatar asked Oct 19 '25 12:10

Ashish


1 Answers

  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.

like image 136
Simone Pontiggia Avatar answered Oct 21 '25 02:10

Simone Pontiggia