const path = require('path');
const isDev = think.env === 'development';
const requestLog = require('../middleware/request_log.js');

module.exports = [
  {
    handle: requestLog,
    options: {}
  },
  {
    handle: 'meta',
    options: {
      logRequest: isDev,
      sendResponseTime: isDev
    }
  },
  {
    handle: 'resource',
    enable: isDev,
    options: {
      root: path.join(think.ROOT_PATH, 'www'),
      publicPath: /^\/(static|favicon\.ico)/
    }
  },
  {
    handle: 'trace',
    enable: !think.isCli,
    options: {
      debug: isDev,
      templates: isDev ? {} : {
        404: path.join(think.ROOT_PATH, 'view/error_404.html'),
        500: path.join(think.ROOT_PATH, 'view/error_500.html')
      }
    }
  },
  {
    handle: 'payload',
    options: {
      keepExtensions: true,
      limit: '5mb'
    }
  },
  {
    handle: 'router',
    options: {}
  },
  'logic',
  'controller'
];
