Skip to content

Commit

Permalink
⚡ 调试打印增加header信息
Browse files Browse the repository at this point in the history
  • Loading branch information
kongnet committed Sep 6, 2019
1 parent 8f62ba8 commit 1d1706d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [0.1.52](https://github.com/kongnet/skybase/compare/v0.1.51...v0.1.52) (2019-09-06)


### :fire:

* 去除模板目录放到git仓库 ([905473f](https://github.com/kongnet/skybase/commit/905473f))



## [0.1.51](https://github.com/kongnet/skybase/compare/v0.1.50...v0.1.51) (2019-09-05)


Expand Down
11 changes: 5 additions & 6 deletions lib/middleware/sky-check-param.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ const api = $G.api = $G.api || {}

const config = require('../../skyconfig')

const apiCheckLog = function (url, obj, method, oldParam) {
const apiCheckLog = function (url, obj, method, oldParam, ctx) {
if (config.logger) {
let checkColor = 'c'
obj = obj || {}
if (obj.code >= 400) { checkColor = 'y' }
let methodStr = method.toUpperCase()
$.log($.c[{ 'GET': 'dimg', 'POST': 'dimy' }[methodStr]](`[ ${methodStr} ]`) + $.c.dimy(url.join ? url.join('/') : url) + $.c[checkColor](JSON.stringify(obj)), oldParam ? $.c.r('实际参数: ' + JSON.stringify(oldParam)) : '')
$.log(oldParam)
$.log($.c[{ 'GET': 'dimg', 'POST': 'dimy' }[methodStr]](`[ ${methodStr} ]`) + $.c.dimy(url.join ? url.join('/') : url) + $.c[checkColor](JSON.stringify(obj || '{}')), '实际参数:', oldParam ? $.c.r(JSON.stringify(oldParam || '{}')) : '', 'header参数:', $.c.r(JSON.stringify(ctx.header || '{}')))
}
}

Expand Down Expand Up @@ -86,7 +85,7 @@ module.exports = async (ctx, next) => {
const apiPath = url.split('?')[0]
const { continue: canContinue, succ, needMethod, apiSetting } = preCheck(ctx, method, url, apiPath)
if (!canContinue) {
apiCheckLog(apiPath, ctx.body, method)
apiCheckLog(apiPath, ctx.body, method, ctx)
return succ ? 1 : 0
}

Expand All @@ -106,9 +105,9 @@ module.exports = async (ctx, next) => {

ctx.checkedData = $.tools.checkParam(params, needMethod === 'all' && apiSetting.param[method] || apiSetting.param)
if (ctx.checkedData.code >= 400) {
apiCheckLog(apiPath, { ...ctx.checkedData, param: params }, method)
apiCheckLog(apiPath, { ...ctx.checkedData, param: params }, method, ctx)
return ctx.throwCode(400, ctx.checkedData.msg)
}
apiCheckLog(apiPath, ctx.checkedData, method, params)
apiCheckLog(apiPath, ctx.checkedData, method, params, ctx)
await next()
}

0 comments on commit 1d1706d

Please sign in to comment.