← スキル一覧に戻る

hive-middleware
by paralect
⭐ 0🍴 0📅 2026年1月18日
SKILL.md
name: hive-middleware description: How to create and use middlewares in Hive framework globs:
- src/middlewares/*.js alwaysApply: false
Middlewares
Location: /src/middlewares/{name}.js
Built-in Middlewares
| Name | Purpose |
|---|---|
allowNoAuth | Skip authentication |
isAuthorized | Require authenticated user |
shouldExist | Load resource, 404 if not found |
attachUser | Load user from token |
Creating Middleware
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;
Using in Endpoints
// 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();
},
];
Global Middleware
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);
});
};
Rules
- Always call
next()or throw - Use
runOrderto control execution order - Factory functions for parameterized middlewares
スコア
総合スコア
50/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です