api-usage-rate
Advanced tools
Comparing version 0.0.1 to 0.1.0
@@ -24,3 +24,3 @@ const path = require('path'); | ||
this.client = new Redis(connectRedis); | ||
if (flushdb) this.client.flushdb(); | ||
if (flushdb) this.client.multi().del(key).del(counter).exec(); | ||
this.ignorePathes = ignorePathes; | ||
@@ -27,0 +27,0 @@ } |
{ | ||
"name": "api-usage-rate", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "An Express-based middleware to trace usage rate of APIs and show them in real time with great visualization tools.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -15,3 +15,3 @@ # api-usage-rate | ||
So I make this tiny tools. No more, no less, just clearly show you the usage rate of APIs. | ||
So I make this tiny tool. No more, no less, just clearly show you the usage rate of APIs. | ||
@@ -52,3 +52,3 @@ With these data, you can | ||
Notes: | ||
- `app.use(apiRate.record());`: this middleware would record every hits of APIs in your redis. Key `api-usage-rate` refers a zset who holds number of hits in field `${req.method}:${req.path}` and key `api-hits-counter` holds sum of hits of all APIs. You can check your redis. | ||
- `app.use(apiRate.record());`: this middleware would record every hits of APIs in your redis. Key `api-usage-rate` refers to a zset who holds number of hits in field `${req.method}:${req.path}` and key `api-hits-counter` holds sum of hits of all APIs. You can check your redis. | ||
- `apiRate.mouteRoutes(app);`: like the comment in example code says, routes `/api-usage-rate` and `/api-data` can be used with your browser once your app is launched. | ||
@@ -63,3 +63,3 @@ | ||
ignorePathes, // Array of RegExp, any req.path tested true with RegExp in the array would be ignore, default to `[/^\/api-data*/, /^\/api-usage-rate*/, /js$/, /css$/]` | ||
flushdb, // whether run `flushdb` while a new instance of class ApiUsageRate is generated, this would flush all api usage data stored in some db of redis, default to false | ||
flushdb, // whether delete data stored in key `api-usage-rate` and `api-hits-counter` while a new instance of class ApiUsageRate is generated, default to false. And don't worry, this switch would not affect other data in redis (since v0.1.0) | ||
}); | ||
@@ -66,0 +66,0 @@ ``` |
14
test.js
@@ -6,5 +6,6 @@ const path = require('path'); | ||
const request = require('supertest'); | ||
const apiRate = new (require('./index.js'))(); | ||
const ApiRate = require('./index.js'); | ||
function makeApp() { | ||
const apiRate = new ApiRate(); | ||
const app = express(); | ||
@@ -17,2 +18,11 @@ app.use(apiRate.record()); | ||
function makeAppWithFlushdb() { | ||
const apiRate = new ApiRate({ flushdb: true }); | ||
const app = express(); | ||
app.use(apiRate.record()); | ||
routes(app, path.join(__dirname, 'controllers')); | ||
apiRate.mouteRoutes(app); | ||
return app; | ||
} | ||
test('GET /tests/1', async (t) => { | ||
@@ -33,3 +43,3 @@ t.plan(4); | ||
t.plan(4); | ||
const app = makeApp(); | ||
const app = makeAppWithFlushdb(); | ||
await request(app).post('/tests/2'); | ||
@@ -36,0 +46,0 @@ |
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
1539
1619836