Reputation: 679
Obviously using cookies makes the most sense for storing the session ID when working with browsers etc, but I'm using Sails just to build up my RESTful API, and I'd like to use a header (X-Session-Identifier or something) to provide the session ID to Sails (this could be returned as a header in the response as well so I know what to then send again).
I assume I need to write some middleware, but I can't find anywhere in the docs where I could hook into.
Do I need to remove connect's cookieSession middleware and replace it with my own?
Upvotes: 2
Views: 1314
Reputation: 173
This is not documented anywhere, but you should be able provide custom middleware to the underlying express object by doing the following:
config/express.js
var sessionware = require('mycoolmiddleware');
modules.exports.express = {
customMiddleware: function (app) {
app.use(sessionware.sessionHeader());
}
};
Sails.js handles this here: https://github.com/balderdashy/sails/blob/v0.9.16/lib/express/index.js#L162
As of Sails.js 0.10.x, they now document how to provide custom middleware here: http://sailsjs.org/#/documentation/concepts/Middleware
Upvotes: 5