Service discovery

服务发现使用说明

安装依赖

npm i @terminus/register-center-client

subscribe

// Pampasfile.js
const { subscribe } = require('@terminus/register-center-client')

const serviceInfoMap = {}
const serviceNames = ['service_a', 'service_b', 'service_c']

module.exports = {
  ...
  async beforeLaunch() {
    await subscribe(serviceNames, serviceInfoMap)
  },
proxy: {
  enable:true,
  router: () => {
    return [ // a array, required if enable set to true and not have match,to. whole path will route when first matched in array.
    {
      match:'/api/.+',
      to: serviceInfoMap['service_a']
    }, {
      match:'/api2/.+',
      to: serviceInfoMap['service_b']
    },{
      match: (ctx) => {
        if(ctx.method === 'POST'){
          ...
          return true;
        }
        return false;
      },
      to: serviceInfoMap['service_c']
    }
  ]
  }
}
}

results matching ""

    No results matching ""