mirror of
https://github.com/strapi/strapi.git
synced 2025-12-28 15:44:59 +00:00
add destroy lifecycle for user + register rateLimit middleware
This commit is contained in:
parent
4e2812321e
commit
7c1c2d43f3
@ -17,4 +17,12 @@ module.exports = {
|
||||
* run jobs, or perform some special logic.
|
||||
*/
|
||||
bootstrap({ strapi }) {},
|
||||
|
||||
/**
|
||||
* An asynchronous destroy function that runs before
|
||||
* your application gets shut down.
|
||||
*
|
||||
* This gives you an opportunity to gracefully stop services you run.
|
||||
*/
|
||||
destroy({ strapi }) {},
|
||||
};
|
||||
|
||||
@ -42,6 +42,7 @@ const draftAndPublishSync = require('./migrations/draft-publish');
|
||||
const LIFECYCLES = {
|
||||
REGISTER: 'register',
|
||||
BOOTSTRAP: 'bootstrap',
|
||||
DESTROY: 'destroy',
|
||||
};
|
||||
|
||||
class Strapi {
|
||||
@ -165,20 +166,9 @@ class Strapi {
|
||||
}
|
||||
|
||||
async destroy() {
|
||||
await this.runLifecyclesFunctions(LIFECYCLES.DESTROY);
|
||||
await this.server.destroy();
|
||||
|
||||
await Promise.all(
|
||||
Object.values(this.plugins).map(plugin => {
|
||||
if (_.has(plugin, 'destroy') && typeof plugin.destroy === 'function') {
|
||||
return plugin.destroy();
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
if (_.has(this, 'admin')) {
|
||||
await this.admin.destroy();
|
||||
}
|
||||
|
||||
this.eventHub.removeAllListeners();
|
||||
|
||||
if (_.has(this, 'db')) {
|
||||
@ -423,7 +413,7 @@ class Strapi {
|
||||
}
|
||||
|
||||
if (this.config.get('autoReload')) {
|
||||
this.server.destroy();
|
||||
this.destroy();
|
||||
process.send('reload');
|
||||
}
|
||||
};
|
||||
@ -460,7 +450,9 @@ class Strapi {
|
||||
}
|
||||
|
||||
// admin
|
||||
await this.admin[lifecycleName]({ strapi: this });
|
||||
if (_.has(this, 'admin')) {
|
||||
await this.admin[lifecycleName]({ strapi: this });
|
||||
}
|
||||
}
|
||||
|
||||
getModel(uid) {
|
||||
|
||||
@ -9,6 +9,7 @@ const srcSchema = yup
|
||||
.shape({
|
||||
bootstrap: yup.mixed().isFunction(),
|
||||
register: yup.mixed().isFunction(),
|
||||
destroy: yup.mixed().isFunction(),
|
||||
})
|
||||
.noUnknown();
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = async (ctx, next) => {
|
||||
module.exports = (settings, { strapi }) => async (ctx, next) => {
|
||||
const ratelimit = require('koa2-ratelimit').RateLimit;
|
||||
|
||||
const message = [
|
||||
|
||||
@ -1,14 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const { rateLimit } = require('../../middlewares');
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
method: 'GET',
|
||||
path: '/connect/(.*)',
|
||||
handler: 'auth.connect',
|
||||
config: {
|
||||
middlewares: [rateLimit],
|
||||
middlewares: ['plugin::users-permissions.rateLimit'],
|
||||
prefix: '',
|
||||
},
|
||||
},
|
||||
@ -17,7 +15,7 @@ module.exports = [
|
||||
path: '/auth/local',
|
||||
handler: 'auth.callback',
|
||||
config: {
|
||||
middlewares: [rateLimit],
|
||||
middlewares: ['plugin::users-permissions.rateLimit'],
|
||||
prefix: '',
|
||||
},
|
||||
},
|
||||
@ -26,7 +24,7 @@ module.exports = [
|
||||
path: '/auth/local/register',
|
||||
handler: 'auth.register',
|
||||
config: {
|
||||
middlewares: [rateLimit],
|
||||
middlewares: ['plugin::users-permissions.rateLimit'],
|
||||
prefix: '',
|
||||
},
|
||||
},
|
||||
@ -43,7 +41,7 @@ module.exports = [
|
||||
path: '/auth/forgot-password',
|
||||
handler: 'auth.forgotPassword',
|
||||
config: {
|
||||
middlewares: [rateLimit],
|
||||
middlewares: ['plugin::users-permissions.rateLimit'],
|
||||
prefix: '',
|
||||
},
|
||||
},
|
||||
@ -52,7 +50,7 @@ module.exports = [
|
||||
path: '/auth/reset-password',
|
||||
handler: 'auth.resetPassword',
|
||||
config: {
|
||||
middlewares: [rateLimit],
|
||||
middlewares: ['plugin::users-permissions.rateLimit'],
|
||||
prefix: '',
|
||||
},
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user