Giter Site home page Giter Site logo

bonus-common-mw's Introduction

nodejs各服务的一些重复代码封装

暴露对象 {CommonMiddleware,EurekaClient,API,services}

  • CommonMiddleware:KOA中间件,封装使用了一些项目中通用的中间件
  • EurekaClient : 用于注册服务中心和获取服务中心句柄的对象
  • API: 提供业务服务的overlay网络调用地址(修改注册Eureka后抛弃)
  • services:提供业务服务的名称和信息键值对

CommonMiddleware

调用方式:CommonMiddleware(options object),将会自动添加公用中间件

options配置:

  • app:koa对象,必传
  • serviceName:服务名,可以理解为appName,必传

EurekaClient

EurekaClient对象包含两部分

module.exports = {
    registrEureka,
    client
}

client:object,提供一个getServerByAppName获取其它服务的实例,此操作应发生在registrEureka之后,具体见registrEureka说明 registrEureka(serviceName,port):function,向注册中心注册服务,serviceName是服务名,port是服务端口。registrEureka为异步操作,完成后才会对client对象赋值,故使用client.getServerByAppName方法需要在实际操作发生时。

API

services

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.