在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:detectiveHLH/koa2-response开源软件地址:https://github.com/detectiveHLH/koa2-response开源编程语言:JavaScript 100.0%开源软件介绍:A middleware which can let you send your response easier in Koa. koa2-responseInstallnpm install koa2-response Usageconst koa = require('koa');
const app = new koa();
const router = require('koa-router')();
const response = require('koa2-response');
// Defining error code map
const code = {
UNKNOWN_ERROR: [1, 'Sorry, you seem to have encountered some unknown errors.']
};
// Use this middleware
app.use(response);
router
.get('/', (ctx, next) => {
// Instead of "ctx.body = {};"
ctx.success({
name: 'test'
})
})
.get('/error_test', (ctx, next) => {
ctx.error(code.UNKNOWN_ERROR);
})
.get('/throw', (ctx, next) => {
ctx.throw(500, 'Internal Server Error');
});
app.use(router.routes());
app.use(router.allowedMethods());
app.listen(3000);
console.log(`Server is running on port 3000`); Licences |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论