Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
masasron committed Nov 17, 2017
1 parent f38301d commit 4e6351a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Once Adonis Throttle is installed, you need to register the service provider.
Open up bootstrap/app.js and add the following to the providers key.

```js
// bootstrap/app.js
// start/app.js
const providers = [
...,
'adonis-throttle/providers/ThrottleProvider',
Expand All @@ -23,7 +23,7 @@ const providers = [
You can register the Throttle facade in the aliases key of your bootstrap/app.js file if you like.

```js
// bootstrap/app.js
// start/app.js
const aliases = {
...,
Throttle: 'Adonis/Addons/Throttle'
Expand All @@ -33,7 +33,7 @@ const aliases = {
Enable the throttle middleware inside `app/Http/kernel.js` file.

```js
// app/Http/kernel.js
// start/kernel.js

const namedMiddleware = {
...,
Expand Down
4 changes: 2 additions & 2 deletions middleware/ThrottleRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ThrottleRequests {
*
* @public
*/
* handle(request, response, next, maxAttempts = 60, decayInSeconds = 60, uid = false) {
async handle({request, response}, next, maxAttempts = 60, decayInSeconds = 60, uid = false) {
const signature = this._resolveSignature(request, uid)
this.throttle.resource(signature, parseInt(maxAttempts), parseInt(decayInSeconds))

Expand All @@ -53,7 +53,7 @@ class ThrottleRequests {
this.throttle.remainingAttempts()
)

yield next
await next()
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adonis-throttle",
"version": "1.0.5",
"version": "2.0.1",
"description": "A rate limiter for Adonis JS",
"main": "src/Throttle.js",
"scripts": {
Expand Down
12 changes: 6 additions & 6 deletions providers/ThrottleProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
* file that was distributed with this source code.
*/

const ServiceProvider = require('adonis-fold').ServiceProvider
const { ServiceProvider } = require('@adonisjs/fold')

const Throttle = require('../src/Throttle')
const Cache = require('../src/Drivers/Cache/Memory')
const ThrottleRequests = require('../middleware/ThrottleRequests')


class ThrottleProvider extends ServiceProvider {

* register() {
this.app.singleton('Adonis/Addons/Throttle', function () {
register() {
this.app.singleton('Adonis/Addons/Throttle', () => {
return new Throttle(new Cache())
})
this.app.bind('Adonis/Middleware/Throttle', function (app) {
})

this.app.bind('Adonis/Middleware/Throttle', (app) => {
return new ThrottleRequests(app.use('Adonis/Addons/Throttle'))
})
}
Expand Down
1 change: 0 additions & 1 deletion src/Drivers/Cache/Memory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Cache {
this.data = {}
this.timers = {}
this.expirations = {}
console.log('cache was init')
}

/**
Expand Down

0 comments on commit 4e6351a

Please sign in to comment.