waibu 2.12.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -18,10 +18,10 @@ const onRequest = {
|
|
|
18
18
|
const ip = plain ? this.getIp(req) : chalk.magenta(this.getIp(req))
|
|
19
19
|
let msg = this.app[ns].t('httpReq%s%s%s%s', arrow, method, url.replaceAll('%', '%%'), ip)
|
|
20
20
|
if (req.headers['content-length']) msg += this.app[ns].t('httpReqExt%s', req.headers['content-length'])
|
|
21
|
-
if (this.config.
|
|
21
|
+
if (this.config.log.defer) {
|
|
22
22
|
this.reqLog = this.reqLog ?? {}
|
|
23
23
|
this.reqLog[req.id] = msg
|
|
24
|
-
} else this.app[ns].log.info(msg)
|
|
24
|
+
} else if (!this.config.log.noReq) this.app[ns].log.info(msg)
|
|
25
25
|
if (Object.keys(this.config.paramsCharMap).length === 0) return
|
|
26
26
|
for (const key in req.params) {
|
|
27
27
|
let val = req.params[key]
|
|
@@ -36,12 +36,12 @@ const onResponse = {
|
|
|
36
36
|
if (elapsed < 1000) tc = 'yellow'
|
|
37
37
|
if (elapsed < 500) tc = 'green'
|
|
38
38
|
const time = plain ? elapsed.toFixed(2) : chalk[tc](elapsed.toFixed(2))
|
|
39
|
-
if (this.config.
|
|
39
|
+
if (this.config.log.defer) {
|
|
40
40
|
this.reqLog = this.reqLog ?? {}
|
|
41
|
-
if (this.reqLog[req.id]) this.app[ns].log.info(this.reqLog[req.id])
|
|
41
|
+
if (this.reqLog[req.id] && !this.config.log.noReq) this.app[ns].log.info(this.reqLog[req.id])
|
|
42
42
|
delete this.reqLog[req.id]
|
|
43
43
|
}
|
|
44
|
-
this.app[ns].log[level]('httpResp%s%s%s%s%s', arrow, method, url, state, time)
|
|
44
|
+
if (!this.config.log.noReply) this.app[ns].log[level]('httpResp%s%s%s%s%s', arrow, method, url, state, time)
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
package/index.js
CHANGED
|
@@ -91,7 +91,11 @@ async function factory (pkgName) {
|
|
|
91
91
|
intl: {
|
|
92
92
|
detectors: ['qs']
|
|
93
93
|
},
|
|
94
|
-
|
|
94
|
+
log: {
|
|
95
|
+
noReq: false,
|
|
96
|
+
noReply: false,
|
|
97
|
+
defer: false
|
|
98
|
+
},
|
|
95
99
|
prefixVirtual: '~',
|
|
96
100
|
qsKey: {
|
|
97
101
|
bbox: 'bbox',
|
|
@@ -215,9 +219,9 @@ async function factory (pkgName) {
|
|
|
215
219
|
* @param {string} name - ns based route name
|
|
216
220
|
* @returns {Object} Route object
|
|
217
221
|
*/
|
|
218
|
-
findRoute = (name) => {
|
|
222
|
+
findRoute = (name, method = 'GET') => {
|
|
219
223
|
const { outmatch } = this.app.lib
|
|
220
|
-
const { find } = this.app.lib._
|
|
224
|
+
const { find, isString } = this.app.lib._
|
|
221
225
|
const { breakNsPath } = this.app.bajo
|
|
222
226
|
let { ns, subNs = '', path } = breakNsPath(name)
|
|
223
227
|
const params = path.split('|')
|
|
@@ -227,7 +231,8 @@ async function factory (pkgName) {
|
|
|
227
231
|
r.config = r.config ?? {}
|
|
228
232
|
const match = outmatch(r.config.pathSrc ?? r.path, { separator: false })
|
|
229
233
|
if (!match(path)) return false
|
|
230
|
-
|
|
234
|
+
const methods = isString(r.method) ? [r.method] : r.method
|
|
235
|
+
return ns === r.config.ns && r.config.subNs === subNs && methods.includes(method)
|
|
231
236
|
})
|
|
232
237
|
}
|
|
233
238
|
|
package/lib/build-locals.js
CHANGED
|
@@ -73,7 +73,6 @@ async function buildLocals ({ tpl, params = {}, opts = {} } = {}) {
|
|
|
73
73
|
_meta.template = tpl
|
|
74
74
|
_meta.hostHeader = req.headers.host
|
|
75
75
|
_meta.statusCode = 200
|
|
76
|
-
_meta.isAdmin = _meta.user && find(_meta.user.teams, { alias: 'administrator' })
|
|
77
76
|
const pulled = []
|
|
78
77
|
for (const k in errs) {
|
|
79
78
|
if (Date.now() - errs[k] > 5000) pulled.push(k)
|
|
@@ -89,12 +88,14 @@ async function buildLocals ({ tpl, params = {}, opts = {} } = {}) {
|
|
|
89
88
|
}
|
|
90
89
|
errs[req.id] = Date.now()
|
|
91
90
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
_meta.flash = reply && req.session && req.flash && !opts.partial && !opts.noFlash ? reply.flash() : {}
|
|
92
|
+
if (!opts.partial) {
|
|
93
|
+
set(params, 'menu.homes', await buildHomesMenu.call(this, req))
|
|
94
|
+
set(params, 'menu.pages', await buildPagesMenu.call(this, req))
|
|
95
|
+
}
|
|
95
96
|
const merged = merge({}, params, { _meta })
|
|
96
|
-
await runHook(`${this.ns}:afterBuildLocals`, merged, req)
|
|
97
|
-
if (!isEmpty(routeOpts.ns)) await runHook(`${this.ns}.${routeOpts.ns}:afterBuildLocals`, merged, req)
|
|
97
|
+
await runHook(`${this.ns}:afterBuildLocals`, merged, req, opts)
|
|
98
|
+
if (!isEmpty(routeOpts.ns)) await runHook(`${this.ns}.${routeOpts.ns}:afterBuildLocals`, merged, req, opts)
|
|
98
99
|
return merged
|
|
99
100
|
}
|
|
100
101
|
|
package/lib/decorate.js
CHANGED
|
@@ -4,6 +4,7 @@ async function decorate () {
|
|
|
4
4
|
const me = this
|
|
5
5
|
this.instance.decorateRequest('lang', null)
|
|
6
6
|
this.instance.decorateRequest('t', () => {})
|
|
7
|
+
this.instance.decorateRequest('te', () => {})
|
|
7
8
|
this.instance.decorateRequest('format', () => {})
|
|
8
9
|
this.instance.decorateRequest('langDetector', null)
|
|
9
10
|
this.instance.decorateRequest('site', null)
|
package/lib/handle-error.js
CHANGED
|
@@ -2,9 +2,9 @@ import { redirect } from './handle-redirect.js'
|
|
|
2
2
|
import { notFound, writeHtml, interceptor } from './handle-not-found.js'
|
|
3
3
|
|
|
4
4
|
async function error (err, req, reply) {
|
|
5
|
-
this.log.error(err)
|
|
6
5
|
const resp = await interceptor.call(this, 'errorHandler', err, req, reply)
|
|
7
6
|
if (resp) return resp
|
|
7
|
+
this.log.error(err)
|
|
8
8
|
const payload = {
|
|
9
9
|
text: this.app.log.getErrorMessage(err),
|
|
10
10
|
title: req.t('internalServerError')
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-05-22
|
|
4
|
+
|
|
5
|
+
- [2.13.0] Add ```config.log.noReq``` & ```config.log.noReply```
|
|
6
|
+
- [2.13.0] Change ```config.deferLog``` to ```config.log.defer```
|
|
7
|
+
- [2.13.0] Bug fix in ```build-Locals.js```
|
|
8
|
+
- [2.13.0] Add ```decorator.te```
|
|
9
|
+
- [2.13.0] Bug fix in ```handle-error.js```
|
|
10
|
+
|
|
3
11
|
## 2026-05-16
|
|
4
12
|
|
|
5
13
|
- [2.12.0] Change in ```routeDir()```
|