Hi,
Thanks for this tutorial. I’m confused about where the strapi object comes from within the controller. For example, in this snippet, on line 4:
module.exports = {
async postsReport(ctx, next) {
try {
const data = await strapi // where'd this come from?
.service("api::posts-report.posts-report")
.postsReport();
console.log(data, "data");
ctx.body = data;
} catch (err) {
ctx.badRequest("Post report controller error", { moreDetails: err });
}
},
};
At first I thought this was a typo in the code snippet as strapi appears to be an undefined global variable. But then I saw the same thing repeated in other docs and realized that, lo and behold, this just works:
export default {
async index(ctx, next) {
console.log(strapi); // Strapi { ... }
// called by GET /hello
ctx.body = "Hello World!"; // we could also send a JSON
},
};
Can somebody point me to any documentation for this magic global object?
I am just diving into Strapi and this really confused me. Especially since strapi is provided as an argument to the callback function when you use a factory to create a core controller – is that the same strapi that I logged above? why is it provided in a callback for core controllers but not custom ones?