sails-hook-allowed-hosts
v1.0.1
Published
Sails hook to ensure that only requests made from authorized hosts/IP addresses are allowed
Downloads
27
Maintainers
Readme
sails-hook-allowed-hosts
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');
}
};