Skip to content

Instantly share code, notes, and snippets.

@skinofstars
Created June 13, 2019 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skinofstars/246eb4ac9417c5c32f8dc4e2dbf259bd to your computer and use it in GitHub Desktop.
Save skinofstars/246eb4ac9417c5c32f8dc4e2dbf259bd to your computer and use it in GitHub Desktop.
FeathersJS - Demo of services picking up each others hooks
module.exports = function(app) {
class BeepBoop {
async update(id, data, params) {
console.log("BeepBoop", id, params);
// passing params here will also pass the route.id
await app.service("zap").update("456", {}, params);
return Promise.resolve();
}
}
app.use("beep/:id/boop", new BeepBoop()).hooks({
before: {
update: context => {
if (context.params.route && context.params.route.id) {
context.id = context.params.route.id;
}
}
}
});
class Zap {
update(id, data, params) {
console.log("Zap", id);
return Promise.resolve();
}
}
app.use("zap", new Zap());
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment