Skip to content

Instantly share code, notes, and snippets.

@skinofstars
Last active May 2, 2017 13:37
Show Gist options
  • Save skinofstars/60a8197a04cd6f42499e2a4bcabf97aa to your computer and use it in GitHub Desktop.
Save skinofstars/60a8197a04cd6f42499e2a4bcabf97aa to your computer and use it in GitHub Desktop.
Feathers schema switching in sequelize
// setup a middleware that provides access to the express headers
module.exports = (req, res, next) => {
req.feathers.headers = req.headers;
next();
};
// update the model schema based on express passed headers
module.exports = function() {
return function(hook) {
if (hook.params.headers.subdomain) {
hook.service.Model = hook.service.Model.schema(
hook.params.headers.subdomain,
);
} else {
throw new Error('subdomain header missing');
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment