resource-router-middleware
resource-router-middleware copied to clipboard
Nested resource use
Can it be use for nested resource? e.g like Laravel https://laravel.com/docs/5.1/controllers#restful-nested-resources.
If I have route like photos/:photos/comments/:comments how will I use your package?
app.use('/photos/:photo', resource({
id: 'comment',
mergeParams: true,
load(req, id, callback) {
const { photo } = req.params;
comments.find({ id, photo_id:photo })
.then(callback.bind(null,null))
.catch(callback);
},
async list(req, res) {
req.photo. // The photo ID
res.json(await comments.find({photo_id:req.photo}));
}
}));