Created
June 13, 2019 10:03
-
-
Save skinofstars/246eb4ac9417c5c32f8dc4e2dbf259bd to your computer and use it in GitHub Desktop.
FeathersJS - Demo of services picking up each others hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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