|
|
|
@@ -18,11 +18,17 @@ const WHITE_LIST = [ |
|
|
|
|
|
|
|
module.exports = class extends think.Controller { |
|
|
|
async __before() { |
|
|
|
console.log('[TEST-CONSOLE] base __before 被调用, path:', this.ctx.path); |
|
|
|
think.logger.info('[TEST-LOGGER] base __before 被调用, path:', this.ctx.path); |
|
|
|
|
|
|
|
const path = this.ctx.path; |
|
|
|
|
|
|
|
// 记录请求开始时间 |
|
|
|
this._requestStart = Date.now(); |
|
|
|
const dayjs = require('dayjs'); |
|
|
|
const params = { ...this.get(), ...this.post() }; |
|
|
|
console.log('=================== 请求开始 ==================='); |
|
|
|
console.log(`path: ${path}`); |
|
|
|
console.log(`params: ${JSON.stringify(params)}`); |
|
|
|
console.log(`time: ${dayjs().format('YYYY-MM-DD HH:mm:ss')}`); |
|
|
|
|
|
|
|
// 白名单放行(同时匹配带.html后缀的路径) |
|
|
|
const pathNoSuffix = path.replace(/\.html$/, ''); |
|
|
|
if (WHITE_LIST.includes(path) || WHITE_LIST.includes(pathNoSuffix)) { |
|
|
|
@@ -67,6 +73,15 @@ module.exports = class extends think.Controller { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async __after() { |
|
|
|
const dayjs = require('dayjs'); |
|
|
|
const elapsed = ((Date.now() - (this._requestStart || Date.now())) / 1000).toFixed(3); |
|
|
|
console.log(`result: ${JSON.stringify(this.ctx.body || '').slice(0, 500)}`); |
|
|
|
console.log(`time: ${dayjs().format('YYYY-MM-DD HH:mm:ss')}`); |
|
|
|
console.log(`耗时: ${elapsed}秒`); |
|
|
|
console.log('=================== 请求结束 ==================='); |
|
|
|
} |
|
|
|
|
|
|
|
// 加载用户权限 |
|
|
|
async loadUserPermissions() { |
|
|
|
if (!this.adminUser) return; |
|
|
|
|