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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@micl/server-express-middlewares

v0.1.3

Published

micl server express middlewares

Readme

@micl/server-express-middlewares

npm version npm downloads license

Micl 项目的 Express 中间件集合,提供 JWT 认证、SSE (Server-Sent Events) 和任务中心注册等实用功能。

📦 安装

npm install @micl/server-express-middlewares
# or
pnpm add @micl/server-express-middlewares
# or
yarn add @micl/server-express-middlewares

📚 模块导出

| 函数 | 描述 | |------|------| | createAuthMiddleware | 创建 JWT 认证中间件 | | createSSEMiddleware | 创建 SSE (Server-Sent Events) 中间件 |

🎯 使用示例

1. JWT 认证中间件

const express = require('express');
const { createAuthMiddleware } = require('@micl/server-express-middlewares');

const app = express();

// 创建认证中间件
const authMiddleware = createAuthMiddleware({
  secret: 'your-secret-key',  // JWT 密钥
  getToken: (req) => {
    // 自定义 token 获取逻辑
    const auth = req.headers.authorization || '';
    return auth.replace('Bearer ', '');
  },
  authCenter: {
    dns: 'http://auth-center:3000/check-token',  // 认证中心 DNS 地址
    checkToken: checkToken,
  }
});

// 应用中间件
app.use('/api', authMiddleware, (req, res) => {
  // req.user 包含解码后的用户信息
  res.json({
    message: 'Authenticated',
    user: req.user
  });
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

2. SSE (Server-Sent Events) 中间件

const express = require('express');
const { createSSEMiddleware } = require('@micl/server-express-middlewares');

const app = express();

// 创建 SSE 中间件
const sseMiddleware = createSSEMiddleware();

// 应用 SSE 中间件
app.get('/events', sseMiddleware, (req, res) => {
  // 使用 res.sse 发送 SSE 消息
  setInterval(() => {
    res.sse({ time: new Date().toISOString() }, 'time-update');
  }, 1000);

  // 连接关闭时清理
  req.on('close', () => {
    console.log('SSE connection closed');
  });
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

🛠 配置选项

createAuthMiddleware 配置

| 选项 | 类型 | 默认值 | 描述 | |------|------|-------|------| | secret | string | 'default-secret' | JWT 签名密钥 | | getToken | function | 从 Authorization header 获取 | 自定义 token 获取函数 | | authCenter | object | 见下方详细配置 | 认证中心配置 |

authCenter 配置

{
  "dns": "http://auth-center:3000/check-token",
  "checkToken": Function
}

createSSEMiddleware 配置

| 选项 | 类型 | 默认值 | 描述 | |------|------|-------|------| | options | object | {} | 自定义配置选项 |

📁 项目结构

express-middlewares/
├── src/
│   └── core.js        # 核心中间件实现
├── index.js           # 模块导出
├── package.json       # 包配置
├── build.js           # 构建脚本
├── publish.sh         # 发布脚本
└── README.md          # 文档

🛠 开发

构建

# 进入 express-middlewares 目录
cd server-side/express-middlewares

# 构建项目
node build.js

发布

# 发布到 npm
./publish.sh

🤝 贡献

欢迎提交 Issue 和 Pull Request 来完善这个模块。

📄 许可证

本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。

📞 支持

如有问题或建议,请提交 Issue 或联系维护者。


@micl/server-express-middlewares - 实用的 Express 中间件集合 🚀