且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何覆盖Strapi管理面板端点?

更新时间:2023-11-29 23:12:34

分别定义了Strapi管理员(strapi-admin)和内容管理器(strapi-plugin-content-manager).

The Strapi admin(strapi-admin) and Content manager(strapi-plugin-content-manager) are defined separately.

如果您想覆盖/扩展端点;为此,可以定义您要覆盖的函数,如下所示:

If you'd like to override/extend the endpoints; do so by defining the functions you want to override like so:

扩展名/<插件名称>/controllers/< controller-to-override-name> .js

extensions/<plugin-name>/controllers/<controller-to-override-name>.js

示例:

扩展程序/content-manager/controllers/ContentManager.js

extensions/content-manager/controllers/ContentManager.js

*请注意,"strapi-plugin"名称的一部分被删除了!

*Notice that the "strapi-plugin" part of the name was dropped!

示例:

'use strict';
module.exports = {
  
  //this is how you destroy count
  async count(ctx) {
    ctx.body = {
      count: 99
    };
  }
};

要查看哪个端点映射到控制器中的哪个方法,请检出:

To see which endpoint is mapped to which method in the controller check out:

node_modules/<插件名称>/config/routes.json
node_modules/strapi-plugin-content-manager/config/routes.json

node_modules/<plugin-name>/config/routes.json
node_modules/strapi-plugin-content-manager/config/routes.json

文档中的一些基本信息:控制器扩展名

Some basic info in docs: controllers, extensions and FAQ