diff --git a/.changeset/eleven-glasses-greet.md b/.changeset/eleven-glasses-greet.md new file mode 100644 index 0000000..93bf080 --- /dev/null +++ b/.changeset/eleven-glasses-greet.md @@ -0,0 +1,5 @@ +--- +"@pluginpal/webtools-core": patch +--- + +Issue in the router endpoint when querying a single type which does not have localizations enabled. diff --git a/packages/core/server/content-api/services/by-path.ts b/packages/core/server/content-api/services/by-path.ts index 29dad9d..5096315 100644 --- a/packages/core/server/content-api/services/by-path.ts +++ b/packages/core/server/content-api/services/by-path.ts @@ -28,7 +28,7 @@ export default () => ({ excludeDrafts = true; } - const entity = await strapi.entityService.findMany(contentTypeUid, { + const entities = await strapi.entityService.findMany(contentTypeUid, { ...query, filters: { ...query?.filters, @@ -42,12 +42,20 @@ export default () => ({ limit: 1, }); - if (!entity[0]) { + /** + * If we're querying a single type, which does not have localizations enabled, + * Strapi will return a single entity instead of an array. Which is slightly weird, + * because the API we're querying is called `findMany`. That's why we need to check + * if the result is an array or not and handle it accordingly. + */ + const entity = Array.isArray(entities) ? entities[0] : entities; + + if (!entity) { return {}; } return { - entity: entity[0], + entity, contentType: urlAliasEntity.contenttype as Common.UID.ContentType, }; },