Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable some built-in functionality in Sails.js

I'm developing a REST API backend application using Sails.js 0.10 as a framework. This application will be strictly REST, authentication will be implemented using oAuth bearer tokens. All responses will be in JSON format.

Considering this specific requirements I do not need some functionality embedded into Sails.js and I want to remove it from my application (so it will run faster without extraneous code).

So, my question is: How do I disable the following built-in functionality?

  • Blueprints
  • Static
  • Cookies
  • Sessions
  • Views
  • WebSocket
  • CSRF
  • i18n

What else can be disabled that is not required in my use case?

The documentation is kinda fragmented on this specific question. All configuration options are described for each module, but there is no information of how such a module can be disabled and/or removed from the application.

like image 914
Slava Fomin II Avatar asked Jan 18 '15 23:01

Slava Fomin II


1 Answers

Hardcore! You'll need to disable several hooks, and also some middleware. First, in your .sailsrc file, set:

"hooks": {
  "session": false,
  "sockets": false,
  "pubsub": false,
  "views": false,
  "csrf": false,
  "i18n": false,
  "blueprints": false
}

Then in your config/https.js:

middleware: {
  order: [
    'startRequestTimer',
    // 'cookieParser',
    // 'session',
    'bodyParser',
    'handleBodyParserError',
    'compress',
    'methodOverride',
    'poweredBy',
    '$custom',
    'router',
    // 'www',
    // 'favicon',
    '404',
    '500'      
  ]
}

That should get you on your way.

like image 125
sgress454 Avatar answered Oct 03 '22 16:10

sgress454