0.4.1 • Published 7 years ago
@yoctol/axios-logger-mongo v0.4.1
axios-logger-mongo
Mongo logger interceptor for Axios.
Installation
Install using npm:
npm install @yoctol/axios-logger-mongoAPI Reference
| Param | Type | |
|---|---|---|
| mongoURL | String | URL of the mongodb. |
| collectionName | String | Name of the collection. |
| allInstances | Boolean | Support all of axios instances or not. |
| transformRequestBody | Function | Function to map request body. |
| transformResponseBody | Function | Function to map response body. |
Usage
const { useMongoLogger } = require('@yoctol/axios-logger-mongo');
useMongoLogger(axios, {
mongoURL: 'mongodb://localhost:27017/',
collectionName: 'logs',
});To support all of axios instances, set option allInstances to true:
useMongoLogger(axios, {
mongoURL: 'mongodb://localhost:27017/',
collectionName: 'logs',
allInstances: true,
});To transform your request, response before saving to database, use transformRequestBody or transformResponseBody:
useMongoLogger(axios, {
mongoURL: 'mongodb://localhost:27017/',
collectionName: 'logs',
transformRequestBody: (body, { request, config } => { /* */ }),
transformResponseBody: (body, { response, config } => { /* */ }),
});