Edit Page

sails.config.blueprints

These configurable settings allow you to configure the blueprint API in Sails. Some settings (like sails.config.blueprints.autoWatch) control the behavior of built-in blueprint actions, whereas others (like sails.config.blueprints.shortcuts) tweak the behavior of implicit blueprint routing and/or determine whether Sails automatically binds certain kinds of blueprint routes at all.

Remember, blueprint actions can be attached to your custom routes regardless of whether or not you have any kind of implicit blueprint routing enabled.

Properties

Route-related settings
Property Type Default Details
actions false Whether implicit blueprint ("shadow") routes are automatically generated for every action in your app. e.g. having an api/controllers/foo/bar.js file or a bar function in api/controllers/FooController.js would automatically route incoming requests to /foo/bar to that action, as long as it is not overridden by a custom route. When enabled, this setting also binds additional, special implicit ("shadow") routes to any actions named index, and for the relative "root" URL for your app and each of its controllers. For example, a /foo shadow route for api/controllers/foo/index.js, or a / shadow route for api/controllers/index.js.
rest true Automatic REST blueprints enabled? e.g. 'get /:model/:id?' 'post /:model' 'put /:model/:id' 'delete /:model/:id'.
shortcuts true These CRUD shortcuts exist for your convenience during development, but you'll want to disable them in production.: '/:model/find/:id?', '/:model/create', '/:model/update/:id', and '/:model/destroy/:id'.
prefix '' Optional mount path prefix (e.g. '/api/v2') for all blueprint routes, including rest, actions, and shortcuts. This only applies to implicit blueprint ("shadow") routes, not your custom routes.
restPrefix '' Optional mount path prefix for all REST blueprint routes on a controller, e.g. '/api/v2'. (Does not include actions and shortcuts routes.) This allows you to take advantage of REST blueprint routing, even if you need to namespace your RESTful API methods. Will be joined to your prefix config, e.g. prefix: '/api' and restPrefix: '/rest'. RESTful actions will be available under /api/rest.
pluralize false Whether to use plural model names in blueprint routes, e.g. /users for the User model. (This only applies to blueprint autoroutes, not manual routes from sails.config.routes.)
Action-related settings
Property Type Default Details
autoWatch true Whether to subscribe the requesting socket in the find and findOne blueprint action to notifications about newly created records via the blueprint API.
parseBlueprintOptions (See below) Provide this function in order to override the default behavior for blueprint actions (including search criteria, skip, limit, sort and population).
Using parseBlueprintOptions

Each blueprint action includes, at its core, a Waterline model method call. For instance, the find blueprint, when run for the User model, runs User.find() in order to retrieve some user records. The options that are passed to these Waterline methods are determined by a call to parseBlueprintOptions(). The default version of this method (available via sails.hooks.blueprints.parseBlueprintOptions()) determines the default behaviors for blueprints. You can override parseBlueprintOptions in your blueprints config (in config/blueprints.js) to customize the behavior for all blueprint actions, or on a per-route basis to customize the behavior for a single route.

The parseBlueprintOptions() method takes a single argument (the request object) and is expected to return a dictionary of Waterline query options. (You can review an unrealistically-expanded example of a such a dictionary here, but keep in mind that not all keys apply to all blueprint actions. See source code in Sails code for complete details).

Adding your own parseBlueprintOptions() is an advanced concept, and it is recommended that you first familiarize yourself with the default method code and use it as a starting point. For small modifications to blueprint behavior, it is best to first call the default method inside your override and then make changes to the returned query options:

parseBlueprintOptions: function(req) {

  // Get the default query options.
  var queryOptions = req._sails.hooks.blueprints.parseBlueprintOptions(req);

  // If this is the "find" or "populate" blueprint action, and the normal query options
  // indicate that the request is attempting to set an exceedingly high `limit` clause,
  // then prevent it (we'll say `limit` must not exceed 100).
  if (req.options.blueprintAction === 'find' || req.options.blueprintAction === 'populate') {
    if (queryOptions.criteria.limit > 100) {
      queryOptions.criteria.limit = 100;
    }
  }

  return queryOptions;

}

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Sails logo
  • Home
  • Get started
  • Support
  • Documentation
  • Documentation

For a better experience on sailsjs.com, update your browser.

Check out the full Sailsconf 2021 playlist on Youtube

Tweet Follow @sailsjs

Documentation

Reference Concepts App structure | Upgrading Contribution guide | Tutorials More

Reference

  • Application
    • Advanced usage
      • Lifecycle
      • sails.LOOKS_LIKE_ASSET_RX
      • sails.getActions()
      • sails.getRouteFor()
      • sails.lift()
      • sails.load()
      • sails.lower()
      • sails.registerAction()
      • sails.registerActionMiddleware()
      • sails.reloadActions()
      • sails.renderView()
      • sails.request()
      • sails.getBaseUrl()
    • sails.config.custom
    • sails.getDatastore()
    • sails.getUrlFor()
    • sails.log()
  • Blueprint API
    • add to
    • create
    • destroy
    • find one
    • find where
    • populate where
    • remove from
    • replace
    • update
  • Command-line interface
    • sails --version
    • sails console
    • sails debug
    • sails generate
    • sails inspect
    • sails lift
    • sails new
  • Configuration
    • sails.config.*
    • sails.config.blueprints
    • sails.config.bootstrap()
    • sails.config.custom
    • sails.config.datastores
    • sails.config.globals
    • sails.config.http
    • sails.config.i18n
    • sails.config.log
    • sails.config.models
    • sails.config.policies
    • sails.config.routes
    • sails.config.security
    • sails.config.session
    • sails.config.sockets
    • sails.config.views
  • Request (`req`)
    • req._startTime
    • req.body
    • req.cookies
    • req.fresh
    • req.headers
    • req.hostname
    • req.ip
    • req.ips
    • req.isSocket
    • req.method
    • req.options
    • req.originalUrl
    • req.params
    • req.path
    • req.protocol
    • req.query
    • req.secure
    • req.signedCookies
    • req.socket
    • req.subdomains
    • req.url
    • req.wantsJSON
    • req.xhr
    • req.accepts()
    • req.acceptsCharsets()
    • req.acceptsLanguages()
    • req.allParams()
    • req.file()
    • req.get()
    • req.is()
    • req.param()
    • req.setLocale()
    • req.setTimeout()
    • req.host
  • Response (`res`)
    • res.attachment()
    • res.badRequest()
    • res.clearCookie()
    • res.cookie()
    • res.forbidden()
    • res.get()
    • res.json()
    • res.jsonp()
    • res.location()
    • res.notFound()
    • res.ok()
    • res.redirect()
    • res.send()
    • res.serverError()
    • res.set()
    • res.status()
    • res.type()
    • res.view()
    • res.negotiate()
  • Waterline (ORM)
    • Datastores
      • .driver
      • .manager
      • .leaseConnection()
      • .sendNativeQuery()
      • .transaction()
    • Models
      • .addToCollection()
      • .archive()
      • .archiveOne()
      • .avg()
      • .count()
      • .create()
      • .createEach()
      • .destroy()
      • .destroyOne()
      • .find()
      • .findOne()
      • .findOrCreate()
      • .getDatastore()
      • .removeFromCollection()
      • .replaceCollection()
      • .stream()
      • .sum()
      • .update()
      • .updateOne()
      • .validate()
      • .native()
      • .query()
    • Queries
      • .catch()
      • .decrypt()
      • .exec()
      • .fetch()
      • .intercept()
      • .limit()
      • .meta()
      • .populate()
      • .skip()
      • .sort()
      • .then()
      • .tolerate()
      • .toPromise()
      • .usingConnection()
      • .where()
    • Records
      • .toJSON()
  • WebSockets
    • Resourceful PubSub
      • .getRoomName()
      • .publish()
      • .subscribe()
      • .unsubscribe()
    • sails.sockets
      • .addRoomMembersToRooms()
      • .blast()
      • .broadcast()
      • .getId()
      • .join()
      • .leave()
      • .leaveAll()
      • .removeRoomMembersFromRooms()
      • sails.sockets.id()
    • Socket client
      • io.sails
      • io.socket
      • SailsSocket
        • Methods
        • Properties
      • io.socket.delete()
      • io.socket.get()
      • io.socket.off()
      • io.socket.on()
      • io.socket.patch()
      • io.socket.post()
      • io.socket.put()
      • io.socket.request()

Built with Love

The Sails framework is built by a web & mobile shop in Austin, TX, with the help of our contributors. We created Sails in 2012 to assist us on Node.js projects. Naturally we open-sourced it. We hope it makes your life a little bit easier!

Sails:
  • What is Sails?
  • Community
  • News
  • For business
About:
  • Our company
  • Security
  • Legal
  • Logos/artwork
Help:
  • Get started
  • Documentation
  • Docs
  • Contribute
  • Take a class

© 2012-2021 The Sails Company. 
The Sails framework is free and open-source under the MIT License. 
Illustrations by Edamame.