You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Global-sales/wai-server/middleware/components/request_log.middleware.js

19 lines
628 B
JavaScript

const { isEmpty } = require('../../utils/commons.util');
const { createRequestLog } = require('../../services/request_logs.service');
module.exports = async (ctx, next) => {
try {
await next();
if (ctx.method === 'GET' && ['/', '/api/v1/channels/sessions'].includes(ctx.path)) {
return false;
}
await createRequestLog({
method: ctx.method,
path: ctx.method === 'GET' ? ctx.path : ctx.url,
request_data: ctx.method === 'GET' ? (isEmpty(ctx.query) ? null : JSON.stringify(ctx.query)) : JSON.stringify(ctx.request.body),
ip: ctx.ip,
});
} catch (err) {}
};