在管理面板中 - 我有一个内容类型 products
,它向我展示了数据库(MongoDB)中的所有产品
假设我想编辑一个 product
当我点击 Save
按钮,我想点击自定义 API/覆盖更新我的现有端点products
收藏!
是否可以自定义或覆盖管理面板 API?
最佳答案
Strapi 管理员(strapi-admin)和内容管理器(strapi-plugin-content-manager)是分开定义的。
如果您想覆盖/扩展端点;通过定义要覆盖的函数来实现,如下所示:
在以下位置找到 Controller :
extensions/<plugin-name>/controllers/<controller-to-override-name>.js
例子:
extensions/content-manager/controllers/ContentManager.js
请注意,名称的“strapi-plugin”部分已删除!
如何在 Controller 文件中覆盖和扩展的示例:
'use strict';
module.exports = {
//this is how you destroy count
async count(ctx) {
ctx.body = {
count: 99
};
},
//this is how you extend
async aFuncThatDoesntExistInOriginalController(ctx) {
//add logic
},
};
如果您要扩展,则必须添加从路由到 Controller 和方法的映射 要查看哪个端点映射到 Controller 中的哪个方法,请查看:
node_modules/<plugin-name>/config/routes.json
node_modules/strapi-plugin-content-manager/config/routes.json
文档中的一些基本信息:controllers , customization1 & customization2和 FAQ
关于strapi - 如何覆盖 Strapi 管理面板端点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62387941/