Create subfolders in Sails.js /api/controllers

故事扮演 提交于 2019-11-29 10:07:50
Meeker

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

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.

Duc Toan Pham

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!

You're right. It doesn't work out of the box though you can try this approach:

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

Hope it helps!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!