如何覆盖Strapi管理面板端点? [英] How to override Strapi Admin panel endpoints?

查看:242
本文介绍了如何覆盖Strapi管理面板端点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在管理面板中-我有一个内容类型products,它向我显示了数据库(MongoDB)中的所有产品

In the admin panel - I have a content-type products, which shows me all the products in the database (MongoDB)

假设我想编辑一个product,并且当我单击Save按钮时,我想点击一个自定义API/覆盖更新我的现有端点. products收藏!

Suppose I would like to edit a product and when I click on the Save button, I would like to hit a custom API/ override the existing endpoint that updates my products collection!

是否可以自定义或覆盖管理面板API?

Is it possible to customize or override the admin panel APIs?

推荐答案

分别定义了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

这篇关于如何覆盖Strapi管理面板端点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆