mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-03 19:36:20 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			28 lines
		
	
	
		
			578 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			578 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
'use strict';
 | 
						|
const chalk = require('chalk');
 | 
						|
 | 
						|
const codeToColor = code => {
 | 
						|
  return code >= 500
 | 
						|
    ? chalk.red(code)
 | 
						|
    : code >= 400
 | 
						|
    ? chalk.yellow(code)
 | 
						|
    : code >= 300
 | 
						|
    ? chalk.cyan(code)
 | 
						|
    : code >= 200
 | 
						|
    ? chalk.green(code)
 | 
						|
    : code;
 | 
						|
};
 | 
						|
 | 
						|
/**
 | 
						|
 * @type {import('./').MiddlewareFactory}
 | 
						|
 */
 | 
						|
module.exports = (_, { strapi }) => {
 | 
						|
  return async (ctx, next) => {
 | 
						|
    const start = Date.now();
 | 
						|
    await next();
 | 
						|
    const delta = Math.ceil(Date.now() - start);
 | 
						|
 | 
						|
    strapi.log.http(`${ctx.method} ${ctx.url} (${delta} ms) ${codeToColor(ctx.status)}`);
 | 
						|
  };
 | 
						|
};
 |