Search code examples
javascriptnode.jsfeathersjsfeathers-sequelize

How to access the .setup function on a feather-sequelize object?


I want to nest a service behind another one, just as described in the FAQ and this issue

As I understood, you need the .setup property to get access to the app object, on which you can add a listener that you link to your service. So far so good.

However, the service I would need to do that on is not a custom service, on which the setup property is readily available, but a feathers-sequelize service, which seems to be built else where, the .class.js is not even present.

Searching around, I ve seen you can still access the property with the protoype, but not I am reticent in modifying it without knowing it to be something supported.

TL:DR: How to nest a feather-sequelize service behind another one?


Solution

  • You can extend the existing Sequelize ES6 class as documented here:

    const { Service } = require( 'feathers-sequelize');
    
    class MyService extends Service {
      setup(app, path) {
        this.app = app;
        // Do stuff here
      }
    }
    
    app.use('/todos', new MyService({
      paginate: {
        default: 2,
        max: 4
      }
    }));