5

I have API with Sails.js and I want to wrap all my routes in 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
};
Stan
  • 25,744
  • 53
  • 164
  • 242

1 Answers1

1

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". 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.

brittonjb
  • 502
  • 5
  • 15
  • Yea but blueprints is totally not what I want tho. Thanks. – Stan May 16 '15 at 15:02
  • I understand, but just make sure I'm being clear, and in case you didn't know, you don't have to use the REST routes with this, enabling the action blueprints would just give `/cron` the route prefix and the GET, POST, PUT, and DELETE verb routes in the given example. – brittonjb May 16 '15 at 17:35