Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
don't generate default routes when generating plugin api
Signed-off-by: Pierre Noël <pierre.noel@strapi.io>
  • Loading branch information
Pierre Noël committed Mar 24, 2020
commit 760e89fb4a7300b0c3c7da8b43e7f2bd14b2cd32
50 changes: 12 additions & 38 deletions packages/strapi-generate-api/json/routes.json.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,46 +97,20 @@ function generateCollectionTypeRoutes({ route, name }) {
*/

module.exports = scope => {
const routes =
scope.contentTypeKind === 'singleType'
? generateSingleTypeRoutes({
route: scope.route,
name: scope.name,
})
: generateCollectionTypeRoutes({
route: scope.route,
name: scope.name,
});
let routes = [];
if (!scope.args.plugin) {
Copy link
Contributor

@sunnysonx sunnysonx Nov 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @alexandrebodin & @petersg83, What's the reason for disabling the API routes generation inside plugins? Is there any known issue with it? I've deleted that if (!scope.args.plugin) { locally and it seems to generate/merge existing routes for plugins ok.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the plugin models don't get auto generated controllers those default routes point to nothing. There was no reason to generate them :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, it also brokes the functionality of the strapi generate:api order --plugin shop command, which should create a new API inside the plugin, it doesn't generate the routes for it automatically.

routes =
scope.contentTypeKind === 'singleType'
? generateSingleTypeRoutes({ route: scope.route, name: scope.name })
: generateCollectionTypeRoutes({ route: scope.route, name: scope.name });
}

// We have to delete current file
// if routes.json already exists, then merge
if (fs.existsSync(scope.rootPath)) {
let current;

try {
// Copy current routes.json
current = require(scope.rootPath);

// Remove current routes.json
fs.unlinkSync(scope.rootPath);
} catch (e) {
console.error(e);
current = {
routes: [],
};
}

try {
_.set(
current,
'routes',
_.concat(routes, _.differenceWith(current.routes, routes, _.isEqual))
);

return current;
} catch (e) {
console.error(e);
return;
}
console.log('pouet');
let current = require(scope.rootPath);
fs.unlinkSync(scope.rootPath);
routes = _.concat(routes, _.differenceWith(current.routes, routes, _.isEqual));
}

return { routes };
Expand Down