Skip to content

Commit a531c7c

Browse files
committed
fix: never run next() twice in middlewares
1 parent 299a854 commit a531c7c

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

packages/core/server/middlewares/generate-url-alias.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const generateUrlAliasMiddleware: Modules.Documents.Middleware.Middleware = asyn
7171

7272
// If the URL alias has 'generated' set to false, do nothing.
7373
if (urlAliasEntity?.generated === false) {
74-
return next();
74+
return entity;
7575
}
7676

7777
// Fetch the URL alias localizations.
@@ -133,10 +133,24 @@ const generateUrlAliasMiddleware: Modules.Documents.Middleware.Middleware = asyn
133133
});
134134
}));
135135

136-
// Eventually update the entity to include the URL alias.
137-
params.data.url_alias = [urlAliasEntity?.documentId];
136+
const all = await strapi.db.query(uid as 'api::test.test').findMany({
137+
where: {
138+
document_id: entity.documentId,
139+
},
140+
});
141+
142+
await Promise.all(all.map(async (doc) => {
143+
await strapi.db.query(uid as 'api::test.test').update({
144+
where: {
145+
id: doc.id as string,
146+
},
147+
data: {
148+
url_alias: [urlAliasEntity?.id],
149+
},
150+
});
151+
}));
138152

139-
return next();
153+
return entity;
140154
};
141155

142156
export default generateUrlAliasMiddleware;

0 commit comments

Comments
 (0)