Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

sails-hook-allowed-hosts

1.0.1 • Public • Published

sails-hook-allowed-hosts

Build Status Coverage Status

Sails hook to ensure that only requests made from authorized hosts/IP addresses are allowed. Inspired by the ALLOWED_HOSTS setting in Django.

Installation

npm install sails-hook-allowed-hosts --save

Usage

Install the hook and add configuration for it
module.exports.allowedhosts = {
  allowedHosts: [array with strings or regular expression matches for allowed hosts]  // default [/.*/]
  skipEnvs: [array listing environments for which to skip host checking]              // default ['test', 'development']
};

Optionally you can customize the response in case the host doesn't match. By default a 400 badRequest is sent

module.exports.allowedhosts = {
  allowedHosts: [/test\.com/]
  skipEnvs: ['test', 'development']
  errorResponse: function (res) {
    return res.redirect('test.com');
  }
};

Install

npm i sails-hook-allowed-hosts

DownloadsWeekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • avatar