Reputation: 31
What is the best way to implement the following code in sails.js v0.10.5? Should I be handling this with a policy, and if so, how? The init() function required by Stormpath requires Express (app) as an argument. Currently, I am using the following code in sails.config.http.js as custom middleware.
customMiddleware: function(app) { var stormpathMiddleware = require('express-stormpath').init(app, { apiKeyFile: '', application: '', secretKey: '' }); app.use(stormpathMiddleware); }
Upvotes: 3
Views: 730
Reputation: 24958
Yes, this is the preferred way of enabling custom Express middleware with Sails if it does more than just handling a request (as in your case, where .init
requires app
). For simpler cases where you want to implement custom middleware that just handles requests, you can add the handler to sails.config.http.middleware
and also add the handler name to the sails.config.http.middleware.order
array. See the commented out defaults in config/http.js
for an example using myRequestLogger
.
Also note that the $custom
key in the sails.config.http.middleware.order
array indicates where the customMiddleware
code will be executed, so you can change the order if necessary.
Upvotes: 2