feathers-mongoose-casl
Version 2.1.2
Version 2.1.2
  • feathers-mongoose-casl
  • Docs
    • Migrating
    • START A NEW PROJECT
      • Generate a new project.
      • install feathers-mongoose-casl
      • feathers-logger
      • Update config
      • Add mongoose
      • Email service
      • App hooks
      • Import required services
      • Verify user and filter user fields
      • Swagger, Logger, BodyParser
      • Email templates
      • public HTML
      • Run the server
      • Create you first user
      • vs code snippet extension
      • Test Login
      • Dashboard
      • Create a new Service with casl&Dashboard
      • Posts Postman snippet
      • Add Admin role
      • Done!
    • Advanced
      • Security - eslint-plugin-security
      • Security - rate limiting
      • Development tools
    • Guides
      • Throw errors
      • Auth Flow
      • Authentication
      • Authouriztion
      • /me
      • Rules Cache
      • Create a new service
      • Custom service validtor client data
      • validators
        • Example of use
        • Types
        • Mongoose schema
      • Default value
      • $Populate
      • Upload service
      • Upload files
        • Create upload service
        • Sign File After Populate
        • Storage support
          • Google-cloud
      • Error
      • feathers Client examples
      • Dashboard
        • Dashboard Config
          • Field configuration
          • doc Layout
          • custom Fields
            • customElements
        • Online dashboard
        • Add to your react app
      • customized feathers-mongoose-casl/services
      • Redis - in progress
      • S3
      • Postman
      • Swagger
      • debug
    • Production
      • ENV
    • Feathers wiki
      • Good links
    • utils
      • send email example
      • Async For Each
      • Create heroku server
      • pick
      • vs code snippet extension
      • Persist user request
    • Ecosystem
    • TODO
    • Versions updates
Powered by GitBook
On this page

Was this helpful?

  1. Docs
  2. Advanced

Security - rate limiting

PreviousSecurity - eslint-plugin-securityNextDevelopment tools

Last updated 5 years ago

Was this helpful?

Protection middleware for express routes by rate limiting incoming requests

Install express-brute

npm install express-brute express-brute-mongoose --save

create util folder with a new file requestLimitMiddleware.js

const ExpressBrute = require('express-brute');
const MongooseStore = require('express-brute-mongoose');
const BruteForceSchema = require('express-brute-mongoose/dist/schema');
const mongoose = require('mongoose');

const model = mongoose.model(
  'bruteforce',
  new mongoose.Schema(BruteForceSchema)
);
const store = new MongooseStore(model);

const bruteforce = new ExpressBrute(store);

module.exports = bruteforce;

apply as middleware inside your public routes or any route you want to limit

Need to Add " bruteforce.prevent" before createService()

// Initializes the `contact-us` service on path `/contact-us`
const { createService } = require('feathers-mongoose-casl');
const createModel = require('../../models/contact-us.model');
const hooks = require('./contact-us.hooks');
const bruteforce = require('../../utils/requestLimitMiddleware');

module.exports = function (app) {
  const Model = createModel(app);
  const paginate = app.get('paginate');

  const options = {
    Model,
    paginate,
    serviceRules: [
      {'actions': ['create'], 'anonymousUser': true}
    ],

  };

  // Initialize our service with any options it requires
  app.use(
    '/contact-us',
    bruteforce.prevent, // Limit user request
    createService(options)
  );

  // Get our initialized service so that we can register hooks
  const service = app.service('contact-us');

  service.hooks(hooks);
};

You can use others to handle the users request

express-brute
bruteforce adapters