Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create subfolders in Sails.js /api/controllers

here is my problem: I would like to create some subfolders inside /api/controllers in order to organize my source code. My problem there is that as soon as I create a new folder, blueprint api / routes / actions don't seem to work anymore.

From all my tests if I change /api/controller/UserController.js to /api/controller/newpath/UserController.js I can't get the beauty of blueprint working anymore.

Is there any way to do that?

Thanks Emmanuel

like image 498
ecaste Avatar asked Dec 08 '14 23:12

ecaste


3 Answers

You can set this up. Its a bit undocumented, but you can setup a "_config" object on your controller

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

Check out this answer https://stackoverflow.com/a/22062367/1821723

like image 108
Meeker Avatar answered Oct 17 '22 17:10

Meeker


Update January 2016

Since version 0.10.0, you can definitely do this.

The controller identity is its path, in your case newPath/UserController. So a custom route config/routes.js would be something like:

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

Automatic actions still work. You can also create controllers like this with sails generate controller newPath/user.

like image 33
arcseldon Avatar answered Oct 17 '22 18:10

arcseldon


You can config routes.js as below

//application
'post /:api_key/applications'         : 'Threescale.Application.create',
'get /:api_key/check_api_key'         : 'Threescale.Application.check',
'get /:token/manager_list_accounts'   : 'Threescale.Account.list',
'put /:token/manager_approve_account' : 'Threescale.User.activate', 

Under api/controllers, you can manage sub folders and actions as:

Threescale
    Application
        - create.js
        - check.js
    Account
        - list.js
    User
        - activate.js

Hope this is helpful for you!

like image 1
Duc Toan Pham Avatar answered Oct 17 '22 18:10

Duc Toan Pham