Merge pull request #3436 from strapi/fix/403-documentaton

Fix beforeInitialize middlewares can modify order or middlewares
This commit is contained in:
Alexandre BODIN 2019-06-13 09:22:12 +02:00 committed by GitHub
commit 0ceb50ac6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -65,6 +65,20 @@ module.exports = async function() {
});
};
/**
* Run init functions
*/
// Run beforeInitialize of every middleware
await Promise.all(
enabledMiddlewares.map(key => {
const { beforeInitialize } = this.middleware[key].load;
if (typeof beforeInitialize === 'function') {
return beforeInitialize();
}
})
);
// run the initialization of an array of middlewares sequentially
const initMiddlewaresSeq = async middlewareArr => {
for (let key of uniq(middlewareArr)) {
@ -91,20 +105,6 @@ module.exports = async function() {
middlewaresAfter
);
/**
* Run init functions
*/
// Run beforeInitialize of every middleware
await Promise.all(
enabledMiddlewares.map(key => {
const { beforeInitialize } = this.middleware[key].load;
if (typeof beforeInitialize === 'function') {
return beforeInitialize();
}
})
);
// before
await initMiddlewaresSeq(middlewaresBefore);