Hello @mijorus
Create a custom middleware under: ./middlewares/storeResponseTime/index.js with the following code:
'use strict';
module.exports = strapi => {
return {
initialize() {
strapi.app.use(async (ctx, next) => {
const start = Date.now();
await next();
const delta = Math.ceil(Date.now() - start);
//Generate the log here.
let responseTimeLog = {
url: ctx.request.url,
method:ctx.request.method,
responseTime: delta, //response time
};
//Create a custom service that stores your log.
// *responseTimeLog* look like this now:
// { url: '/orders', method: 'GET', time: 16 }
strapi.services.logs.responseTime.create(responseTimeLog);
});
},
};
};
Modify/create the ./config/middleware.js file and add newly created middleware to it.
module.exports = {
load: {
//added it here
before: ['storeResponseTime', 'responseTime', 'logger', 'cors', 'responses', 'gzip'],
order: ["Define the middlewares' load order by putting their name in this array is the right order"],
after: ['parser', 'router'],
},
settings: {
//enable it
storeResponseTime: {
enabled: true,
},
},
};
Also, you can notice that it is returned with headers by default by responseTime middleware.
