1.0.1 • Published 5 years ago

egg-remote-module v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

egg-remote-module

node version NPM version npm download

This egg plugin provides the ability to load remote modules and can be updated via redis without restarting the project.

Install

$ npm i egg-remote-module --save

Usage

// {app_root}/config/plugin.js
exports.remoteModule = {
  enable: true,
  package: 'egg-remote-module',
};
//config/config.default.js
exports.remoteModule = {
  redis: (app) => { return redis.createClient()}, // get redis client
  channel: 'remoteModule', // the redis channel for subscribe
  modules: {
    test: { url: 'http://localhost/public/test.js' },
  },
}
//http://localhost/public/test.js
module.exports = (ctx, params) => {
  return {
    add(a, b){
      return a + b;
    }
  }
}
//{app_root}/app/****.js
const test = await ctx.remote('test', params);
console.log(test.add(1, 2));

Use with egg-redis

When using the egg-redis plugin, you can specify the redis client directly in the configuration.

exports.cache9 = {
  redis: 'remote',
  channel: 'remoteModule',
  modules: {
    test: { url: 'http://localhost/public/test.js' },
  },
};

Configuration

see config/config.default.js for more detail.

License

MIT This README was translate by google