Edit Page

Conventional Defaults

Sails comes bundled with a suite of conventional HTTP middleware, ready to use. You can, of course, disable, override, rearrange, or append to it, but the pre-installed stack is perfectly acceptable for most apps in development or production. Below is a list of the standard HTTP middleware functions that come bundled in Sails, in the order they execute every time the server receives an incoming HTTP request:

HTTP Middleware Key Purpose
startRequestTimer Allocates a variable in memory to hold the timestamp when the request began. This can be accessed and used by your app to provide diagnostic information about slow requests.
cookieParser * Parses the cookie header into a clean object for use in subsequent middleware and your application code.
session * Creates or loads a unique session object (req.session) for the requesting user agent based on their cookies and your session configuration.
bodyParser Parses parameters and binary upstreams (for streaming file uploads) from the HTTP request body using Skipper.
compress Compresses response data using gzip/deflate. See compression for details.
methodOverride Provides faux HTTP method support, letting you use HTTP verbs such as PUT or DELETE in places where the client doesn't support it (e.g. legacy versions of Internet Explorer.) If a request has a _method parameter set to "PUT", the request will be routed as if it was a proper PUT request. See Connect's methodOverride docs for more information if you need it.
poweredBy Attaches an X-Powered-By header to outgoing responses.
$custom Provides backwards compatibility for a configuration option from Sails v0.9.x. Since Sails v0.10 offers much more configuration flexibility for HTTP middleware, as long as you are not using sails.config.express.customMiddleware, you can confidently remove this item from the list.
router * This is where the bulk of your app logic gets applied to any given request. In addition to running "before" handlers in hooks (e.g. csrf token enforcement) and some internal Sails logic, this routes requests using your app's explicit routes (in sails.config.routes) and/or route blueprints.
www * Serves static files- usually images, stylesheets, scripts- in your app's "public" folder (configured in sails.config.paths, conventionally .tmp/public/) using Connect's static middleware.
favicon Serves the browser favicon for your app if one is provided as /assets/favicon.ico.
404 * Handles requests which do not match any routes - triggers res.notFound()
500 * Handles requests which trigger an internal error (i.e. call Express's next(err)) - triggers res.serverError()
Legend:
  • * - The middleware with an asterisk (*) should almost never need to be modified or removed. Please only do so if you really understand what you're doing.

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

Documentation

Reference Concepts App structure | Upgrading Contribution guide | Tutorials More

Concepts

  • Assets
    • Default Tasks
    • Disabling Grunt
    • Task Automation
  • Blueprints
    • Blueprint Actions
    • Blueprint Routes
  • Configuration
    • The local.js file
    • Using `.sailsrc` Files
  • Controllers
    • Generating Controllers
    • Routing to Controllers
  • Custom Responses
    • Adding a Custom Response
    • Default Responses
  • Deployment
    • FAQ
    • Hosting
    • Scaling
  • Extending Sails
    • Adapters
      • Available Adapters
      • Custom Adapters
    • Generators
      • Available Generators
      • Custom Generators
    • Hooks
      • Hook Specification
        • .configure()
        • .defaults
        • .initialize()
        • .routes
      • Installable Hooks
      • Project Hooks
      • Using Hooks
  • File Uploads
    • Uploading to GridFS
    • Uploading to S3
  • Globals
    • Disabling Globals
  • Internationalization
    • Locales
    • Translating Dynamic Content
  • Logging
    • Custom log messages
  • Middleware
    • Conventional Defaults
  • Models and ORM
    • Associations
      • Dominance
      • Many-to-Many
      • One Way Association
      • One-to-Many
      • One-to-One
      • Through Associations
    • Attributes
    • Lifecycle callbacks
    • Model Settings
    • Models
    • Query Language
    • Validations
  • Policies
    • Sails + Passport
  • Programmatic Usage
    • Tips and Tricks
  • Realtime
    • Multi-server environments
    • On the client
    • On the server
  • Routes
    • Custom Routes
    • URL Slugs
  • Security
    • Clickjacking
    • Content Security Policy
    • CORS
    • CSRF
    • DDOS
    • P3P
    • Socket Hijacking
    • Strict Transport Security
    • XSS
  • Services
    • Creating a Service
  • Sessions
  • Testing
  • Views
    • Layouts
    • Locals
    • Partials
    • View Engines

Built with Love

The Sails framework is maintained by a web & mobile studio 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?
  • Treeline IDE
  • Contribute
  • Logos/artwork
About:
  • The Sails Company
  • Security
  • News
  • Legal
Help:
  • Get started
  • Documentation
  • Docs
  • Enterprise
  • Hire us

© 2012-2018 The Sails Company. 
The Sails framework is free and open-source under the MIT License.