matthoiland / restful-api-demo

Code from the video titled "Building a RESTful API in 5 Minutes"
115 stars 45 forks source link

.before/.after not triggering. #9

Closed 0000day closed 7 years ago

0000day commented 7 years ago

Hi.

I'm using the code out of this tutorial: https://github.com/matthoiland/restful-api-demo I've checked the documentation in here https://github.com/baugarten/node-restful which says it is possible to place pre/post functions on every api-call like this:

// Routes
Product.methods(['get', 'put', 'post', 'delete']);
Product.register(router, '/products');

// Pre-Processing
Product.before('get', function (req, res, next) {
    console.log('before triggered');
    next();
});

That function unfortunately never gets called. For sure I also tried it the exact same way as in the documentation by passing an external declared function:

// Pre-Processing
Product.before('get', somethingBefore);

function somethingBefore(req, res, next) {
        console.log('before triggered');
    next();
}

Also nothing happens. Either there is something important missing in the documentation or this is not working as expected to me. (I'm a beginning with everything around node.js).

0000day commented 7 years ago

I had to call register also after the declaration of the pre/post functions.