简体   繁体   English

Sails.js在v1,v2等中分组路由

[英]Sails.js group routes in v1, v2, etc

I have API with Sails.js and I want to wrap all my routes in v1 . 我有Sails.js的API,我想在v1包装所有路由。 Is it possible? 可能吗?

Here is what I tried, but it doesn't work. 这是我尝试过的,但它不起作用。

routes.js

'use strict';

module.exports.routes = {
    '/v1': {                                //
      'get /cron': 'CronController.start'   // THIS DOES NOT WORK
    },                                      //

    'get /cron': 'CronController.start'     // this works
};

Based on my knowledge of Sails the only way to wrap all of your routes in /v1 is to first ensure the actions boolean in config/blueprints.js is set to true (it is by default), and then further down in that file set the prefix string to "/v1" . 根据我对Sails的了解,在/v1包装所有路由的唯一方法是首先确保config/blueprints.js boolean actions设置为true (默认情况下是这样),然后在该文件集中进一步向下prefix字符串为"/v1" Here is the documentation detailing this config . 这是详细说明此配置文档

Note that having the actions boolean set to true causes Sails to generate GET, POST, PUT, and DELETE routes for the action, make sure to use policies to ensure no unsafe logic is exposed in this way. 另外,具有actions的布尔设置为true使帆产生GET,POST,PUT和DELETE路线的动作,确保使用的政策,以确保没有不安全的逻辑以这种方式暴露出来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM