npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

egg-seneca-gateway

v1.0.38

Published

基于 Egg.js + Seneca 的微服务模型,网关插件

Readme

egg-seneca-gateway

NPM version build status Test coverage David deps Known Vulnerabilities npm download

使用说明

插件以Egg.js为应用框架,以Seneca为服务交互支持,提供微服务方案。 整体结构分为两部分:

  • 网关部分:安装插件 egg-seneca-gateway,用以接收外部请求、被动接受子服务嵌入(发现)、提供子服务间交互;
  • 子服务部分: 安装插件 egg-seneca-subserver,子服务开发与普通的 Egg 应用开发无差异,仅配置和启动时机、其他服务交互方式不同。

启动顺序

  1. 先启动 网关 应用,被动等待子服务接入;
  2. 启动 子服务 部分,网关 会生成相应的对外接口、对其他子服务的交互方式;

使用场景

  • 基于 Egg.js + Seneca 的微服务模型, 网关部分。
  • 暂不支持 RESTGraphQL 风格

安装

$ npm i egg-seneca-gateway --save

开启插件

// config/plugin.js
exports.senecaGateway = {
  enable: true,
  package: 'egg-seneca-gateway',
};

详细配置

// {app_root}/config/config.default.js
/**
 * 配置服务器启动项
 */
// 你的服务器定位(必要)
exports.cluster = {
  listen: {
    port: 20980,
    hostname: '127.0.0.1',
  },
};
// seneca gateway 配置
exports.senecaGateway = {
  devLog: true, // 是否显示控制台交互日志, 默认为 false
  server: {
    host: '127.0.0.1',
    port: 50005,
  },
  users: [
    { appid: 'Alalabu', appsecret: 'Thereisagoodboy.' }
  ],
};

服务注册

  • 子服务通过egg-seneca-subserver会解析Egg应用中的Router集合, 并发布于你的网关(安装了egg-seneca-gateway的应用)。
  • 在网关,会生成相应的web API以便客户端调用。
  • 例如你的路由地址是/findAll,而senecaSubserver中配置的server.name=user
  • 则网关会生成: /user/findAll作为统一调用接口

微服务集视图一览

  • 集成视图一览的网关需通过git clone https://github.com/Alalabu/sheu-gateway.git your-gateway进行获取
  • 为方便展示网关可调用服务集合,网关启动后在浏览器输入http://网关主机+端口号/则可以访问微服务集图形界面视图。

服务心跳

  • 每隔 30s 会监测子服务是否依然保持活跃, 若不活跃则删除子服务的访问

服务视图数据

// 可在任何能调用 Egg Application/Agent 对象的地方, 获取当前接入的服务群组数据视图
await app.registryClient.getConfig('SenecaRoutersCache');

更新日记

1.0.37:

  • 增加对 content-type: text/xml 网关数据发放的支持,在网关部分会将 xml 解析成 js 对象,并将子服务请求体改为 content-type: application/json,将 xml 数据作为请求参数封装于POST请求的 ctx.request.body.$options.xml 中,子服务可以判断该值是否存在并直接进行操作。 1.0.35:
  • 配置添加 senecaGateway.devLog = true | false, 用以开启或关闭控制台日志, 默认关闭

License

MIT