用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/paralect/hive --skill hive-middleware命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | hive-middleware |
| description | How to create and use middlewares in Hive framework |
| globs | ["src/middlewares/*.js"] |
| alwaysApply | false |
Location: /src/middlewares/{name}.js
| Name | Purpose |
|---|---|
allowNoAuth | Skip authentication |
isAuthorized | Require authenticated user |
shouldExist | Load resource, 404 if not found |
attachUser | Load user from token |
Simple:
export default async (ctx, next) => {
// Before handler
if (!ctx.state.user?.isAdmin) {
ctx.throw(403, 'Admin only');
}
return next(); // Don't forget!
};
With parameters:
export default (resourceName) => async (ctx, next) => {
const doc = await db.services[resourceName].findOne({
_id: ctx.params[`${resourceName}Id`],
});
if (!doc) ctx.throw(404, `${resourceName} not found`);
ctx.state[resourceName] = doc;
return next();
};
With runOrder (lower runs first):
const middleware = async (ctx, next) => {
ctx.state.isSkipAuth = true;
return next();
};
middleware.runOrder = -1;
export default middleware;
// By name
export const middlewares = ['allowNoAuth'];
// With arguments
export const middlewares = [{ name: 'shouldExist', args: ['projects'] }];
// Direct import
import isAdmin from 'middlewares/isAdmin';
export const middlewares = [isAdmin];
// Factory function
import canEditProject from 'middlewares/canEditProject';
export const middlewares = [canEditProject((ctx) => ctx.params.projectId)];
// Inline
export const middlewares = [
async (ctx, next) => {
// Custom logic
return next();
},
];
Create /src/middlewares/global.js to run on all endpoints:
import isAuthorized from 'middlewares/isAuthorized';
import attachRootProject from 'middlewares/attachRootProject';
export default async (ctx, next) => {
await isAuthorized(ctx, async () => {
await attachRootProject(ctx, next);
});
};
next() or throwrunOrder to control execution order