perf(wai): request log
parent
c53c286a6c
commit
0bc4d4b662
@ -1,15 +1,18 @@
|
||||
const { isEmpty } = require('../../utils/commons.util');
|
||||
const { createRequestLog } = require('../../services/request_logs.service');
|
||||
|
||||
module.exports = async (ctx, next) => {
|
||||
try {
|
||||
await next();
|
||||
} catch (err) {
|
||||
} finally {
|
||||
|
||||
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' ? JSON.stringify(ctx.query) : JSON.stringify(ctx.request.body),
|
||||
request_data: ctx.method === 'GET' ? (isEmpty(ctx.query) ? null : JSON.stringify(ctx.query)) : JSON.stringify(ctx.request.body),
|
||||
ip: ctx.ip,
|
||||
});
|
||||
}
|
||||
} catch (err) {}
|
||||
};
|
||||
|
Loading…
Reference in New Issue