ericholiveira / studio

A nodejs framework to create decoupled and scalable applications
MIT License
488 stars 61 forks source link

How to use plugins #56

Closed sean-hill closed 8 years ago

sean-hill commented 8 years ago

Hey @ericholiveira,

The docs about how to create a plugin are a little unclear. I'm trying to just create one that logs the response of all services, just to get started. Here's what I have so far (copied from one of the example plugins and modified a bit).

module.exports = function (options) {
  'use strict'
  console.log('Plugin loaded')
  options.onStart(function (serv) {
    console.log('Plugin started')
    var _fn = serv.fn
    serv.fn = function () {
      var args = arguments
      return _fn.apply(serv, args).then((res) => {
        console.log('Response:', res)
        return res
      })
    }
  })
}

I then initiate it with:

Studio.use(require('/path/to/plugin')

The log Plugin loaded is fired, but Plugin started is never fired when I use one of my services, neither is Response: <service response>.

I'm just curious how to actually make a plugin. It seems like the boilerplate code is a bit much to create one.

sean-hill commented 8 years ago

Oh nvm, lol. It's because I'm trying to access a service created in another network using Studio cluster. It appears I have to require the plugin in both networks.

ericholiveira commented 8 years ago

Yes... plugins works only locally Em 18/06/2016 6:01 PM, "Sean Hill" notifications@github.com escreveu:

Oh nvm, lol. It's because I'm trying to access a service created in another network using Studio cluster. It appears I have to require the plugin in both networks.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ericholiveira/studio/issues/56#issuecomment-226964614, or mute the thread https://github.com/notifications/unsubscribe/ABKaZF8PBf9RidUjYWoU4oaLalV0Njwdks5qNFy1gaJpZM4I5CBO .