koa-response-middleware
koa response middleware for Koa@2.x, including http status, response header, response body, error handler.
Installation
npm install koa-response-middleware -S
Usage
import * as Koa from 'koa';
import * as handleResponse from 'koa-response-middleware';
const app = new Koa();
app.use(handleResponse({
headers: {
server: 'xxx.com',
},
successInfo: {
version: '1.0.0',
},
errorMessage: 'please contact xxx<xxx@gmail.com>',
isOptions: {
isStatus: true,
isStamp: true,
},
}));
app.use((ctx) => {
ctx.body = {
name: 'handle response',
};
});
API
headers
{Object} set http response headers.successInfo
{Object} wrap http response success bodyerrorMessage
{String} http response error messageisOptions
{Object} wrap http response status code and stamp into response bodyisOptions.isStatusCode
{Boolean} wrap http response status code into response bodyisOptions.isStamp
{Boolean} wrap http response stamp into response body