Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sails.js group routes in v1, v2, etc

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
};
like image 337
Stan Avatar asked Nov 09 '22 17:11

Stan


1 Answers

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.

like image 70
brittonjb Avatar answered Nov 14 '22 23:11

brittonjb