Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override Strapi Admin panel endpoints?

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

enter image description here

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!

enter image description here

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

like image 657
Mahesh Kumaran Avatar asked Jun 15 '20 12:06

Mahesh Kumaran


People also ask

How do I change the Strapi admin logo?

You will find a file called logo-strapi. png (there will be another file with almost similar file name, make sure its a - and not _ ) and replace it with your desired logo. The approx dimens of the old logo as 1100px x 300px , so make sure your new logo also is of similar dimens.

Can I customize Strapi?

The Strapi Design System is fully customizable and has a dedicated StoryBook documentation.

Is Strapi a backend?

Strapi runs an HTTP server based on Koa , a back end JavaScript framework.


Video Answer


1 Answers

Update(v4): Judging by the comments - this answer is now outdated as things have changed for v4.

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:

Locate the controller at:

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

Example:

extensions/content-manager/controllers/ContentManager.js

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

Example of how to override and extend in controller file:

'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
  },
};

If you're extending you must add a mapping from route to controller & method
To see which endpoint is mapped to which method in the controller check out:

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

Some basic info in docs: controllers, customization1 & customization2 and FAQ

like image 136
ghosh Avatar answered Nov 30 '22 15:11

ghosh