egg-guardian will load app/guardian/interrupter to app.guardianInterrupters, load app/guardian/validator to app.guardianInterrupters.
Loader case style is upper, json_interrupter will load to JsonInterrupter.
DefaultInterrupter
JsonInterrupter
Interrupt request, response with JSON content, should set responseStatus(default is 429), responseContent in rule config.
LogInterrupter
Not interrupt request, just print log.
RedirectInterrupter
Interrupt request, redirect to redirectUrl, should set redirectUrl in rule Config.
DefaultValidator
WorkerQpsValidator
If qps is over threshold, mark request should not paas. Should set thresholdMap in rule config.
convert request to requestKey. GET /foo map to GET-/foo
egg-guardian
egg guardian plugin
Install
Usage
Simple - use default validator and interrupter
Use
WorkerQpsJsonRuleResponse 429 and JSON to client.
Use
WorkerQpsRedirectRuleRedirect to specified url.
Use
WorkerQpsLogRule.Print guardian log.
Advanced
GuardianLoader
egg-guardianwill loadapp/guardian/interrupterto app.guardianInterrupters, loadapp/guardian/validatorto app.guardianInterrupters. Loader case style isupper,json_interrupterwill load toJsonInterrupter.DefaultInterrupter
JsonInterrupter
Interrupt request, response with JSON content, should set
responseStatus(default is 429),responseContentin rule config.LogInterrupter
Not interrupt request, just print log.
RedirectInterrupter
Interrupt request, redirect to
redirectUrl, should setredirectUrlin rule Config.DefaultValidator
WorkerQpsValidator
If qps is over threshold, mark request should not paas. Should set
thresholdMapin rule config.requestKey.GET /foomap toGET-/foorequestKeyqps.Define custom validator and interrupter.
module.exports = app => { class CustomValidator extends app.GuardianValidator { /** * @constructor * @params {object} options - * @params {Application} options.app - * @params {object} config - rule config.
config.guardian.rules.rule*/ constructor(options) { super(options); this.counter = 0; // ready(true) is required. Rule will wait to validator is ready. this.ready(true); }} };
License
MIT