Creating subfolders in Sails.js / api / controller

here is my problem: I would like to create some subfolders inside / api / controller to streamline the source code. My problem is that as soon as I create a new folder, the api / routes / actions drawings do not work.

Of all my tests, if I change /api/controller/UserController.js to / api / controller / newpath / UserController.js, I can no longer get the beauty of the drawing.

Is there any way to do this?

Thanks Emmanuel

+6
source share
3 answers

You can install it. Its a little undocumented, but you can configure the "_config" object on your controller

api/controllers/subFolder/YourController.js ... module.exports = { _config: { model: 'YourModel' // case sensitive actions: true, shortcuts: true, rest: true } } 

Check this answer fooobar.com/questions/979302 / ...

+6
source

January 2016 Update

Starting with version 0.10.0, you can do this.

The controller ID is its path, in your case newPath/UserController . So the custom config/routes.js would look something like this:

 'GET /newPath/user': 'newPath/UserController' 

Automatic actions still work. You can also create such controllers using sails generate controller newPath/user .

+5
source

You're right. This does not work out of the box, although you can try this approach:

In models/User.js set identity: "newpath/user"

Hope this helps!

-2
source

Source: https://habr.com/ru/post/979298/


All Articles