@jota-one/drosse
Advanced tools
Comparing version 1.10.0 to 1.11.0
@@ -19,12 +19,19 @@ const proxy = require('http-proxy-middleware') | ||
const getThrottleMiddleware = def => { | ||
return (req, res, next) => { | ||
if (!def.throttle) { | ||
return next() | ||
} | ||
setTimeout( | ||
next, | ||
getThrottle(def.throttle.min || 0, def.throttle.max || def.throttle.min) | ||
) | ||
} | ||
} | ||
const setRoute = function (app, def, verb, root) { | ||
app[verb]( | ||
'/' + root.join('/'), | ||
getThrottleMiddleware(def), | ||
(req, res, next) => { | ||
if (!def.throttle) { | ||
return next() | ||
} | ||
setTimeout(next, getThrottle(def.throttle.min, def.throttle.max)) | ||
}, | ||
(req, res, next) => { | ||
let response | ||
@@ -140,2 +147,3 @@ | ||
}, | ||
def, | ||
}) | ||
@@ -207,7 +215,8 @@ } | ||
app.proxies.forEach(({ path, context }) => { | ||
app.use( | ||
path || '/', | ||
proxy.createProxyMiddleware({ ...context, logLevel: 'warn' }) | ||
) | ||
app.proxies.forEach(({ path, context, def }) => { | ||
const middlewares = [ | ||
getThrottleMiddleware(def), | ||
proxy.createProxyMiddleware({ ...context, logLevel: 'warn' }), | ||
] | ||
app.use(path || '/', middlewares) | ||
@@ -214,0 +223,0 @@ logger.info(`-> PROXY ${path || '/'} => ${context.target}`) |
@@ -1,14 +0,1 @@ | ||
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
# [1.10.0](https://github.com/jota-one/drosse/compare/v1.8.0...v1.10.0) (2021-01-20) | ||
**Note:** Version bump only for package @jota-one/drosse | ||
# Changelog | ||
@@ -21,2 +8,10 @@ All notable changes to this project will be documented in this file. | ||
## [Unreleased] | ||
empty | ||
## [1.11.0] - 2021-02-12 | ||
### Added | ||
- Allow throttle for proxied routes | ||
- Allow to define throttle only with min or max | ||
## [1.10.0] - 2021-01-20 | ||
### Changed | ||
@@ -89,3 +84,5 @@ - Changed the proxy configuration to make it actually usable intuitively. From now, the URL path to where the proxy is defined is removed from the proxied path. | ||
[Unreleased]: https://github.com/jota-one/drosse/compare/1.9.0...develop | ||
[Unreleased]: https://github.com/jota-one/drosse/compare/1.11.0...develop | ||
[1.11.0]: https://github.com/jota-one/drosse/compare/1.10.0...1.11.0 | ||
[1.10.0]: https://github.com/jota-one/drosse/compare/1.9.0...1.10.0 | ||
[1.9.0]: https://github.com/jota-one/drosse/compare/1.8.0...1.9.0 | ||
@@ -92,0 +89,0 @@ [1.8.0]: https://github.com/jota-one/drosse/compare/1.7.0...1.8.0 |
@@ -5,2 +5,6 @@ { | ||
"DROSSE": { | ||
"throttle": { | ||
"min": 3000, | ||
"max": 3000 | ||
}, | ||
"get": { | ||
@@ -51,4 +55,13 @@ "body": [{ | ||
} | ||
}, | ||
"countries-slow": { | ||
"DROSSE": { | ||
"proxy": "https://restcountries.eu/rest/v2", | ||
"throttle": { | ||
"min": 2000, | ||
"max": 4000 | ||
} | ||
} | ||
} | ||
} | ||
} |
{ | ||
"check-session": { | ||
"DROSSE": { | ||
"get": { | ||
"body": { | ||
"connected": true | ||
} | ||
"DROSSE": { | ||
"get": { | ||
"body": { | ||
"connected": true | ||
} | ||
@@ -9,0 +7,0 @@ } |
{ | ||
"name": "@jota-one/drosse", | ||
"version": "1.10.0", | ||
"version": "1.11.0", | ||
"description": "Mock your backend the right way.", | ||
@@ -5,0 +5,0 @@ "main": "app/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
75
1633
651479