diff --git a/.changeset/fix-async-router-controller.md b/.changeset/fix-async-router-controller.md new file mode 100644 index 00000000..06167060 --- /dev/null +++ b/.changeset/fix-async-router-controller.md @@ -0,0 +1,7 @@ +--- +"strapi-plugin-webtools": patch +--- + +Fix async handling in router controller + +Add await keyword before transformResponse call to properly handle the Promise returned by the method. This resolves the issue where the router endpoint returns empty objects instead of the expected content. \ No newline at end of file diff --git a/packages/core/server/controllers/core.ts b/packages/core/server/controllers/core.ts index 69a2c946..306baff6 100644 --- a/packages/core/server/controllers/core.ts +++ b/packages/core/server/controllers/core.ts @@ -35,7 +35,7 @@ export default { // Format response. const sanitizedEntity = await sanitizeOutput(responseEntity, contentTypeObj, auth); - ctx.body = strapi.controller(contentType as UID.Controller) + ctx.body = await strapi.controller(contentType as UID.Controller) // @ts-expect-error // The strapi object is typed in a way that the following is expected to be a controller. // In fact that is not true, as this also exposes the helper functions of the controller.