mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-16 02:42:57 +08:00
Add middlewares for API and various improvements (#685)
This commit is contained in:
13
middleware/api-template.js
Normal file
13
middleware/api-template.js
Normal file
@@ -0,0 +1,13 @@
|
||||
module.exports = async (ctx, next) => {
|
||||
await next();
|
||||
if (ctx.request.path.startsWith('/api/')) {
|
||||
if (ctx.body.counter > 0) {
|
||||
return ctx.res.ok({
|
||||
message: `request returned ${ctx.body.counter} ${ctx.body.counter > 1 ? 'routes' : 'route'}`,
|
||||
data: ctx.body.result,
|
||||
});
|
||||
} else {
|
||||
return ctx.res.noContent();
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user