waibu 2.15.0 → 2.15.2

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.
@@ -6,6 +6,13 @@ export const methodColor = {
6
6
  DELETE: 'red'
7
7
  }
8
8
 
9
+ const stateColor = {
10
+ 2: 'green',
11
+ 3: 'yellow',
12
+ 4: 'red',
13
+ 5: 'red'
14
+ }
15
+
9
16
  async function hook () {
10
17
  return [{
11
18
  name: 'waibu:onClose',
@@ -50,6 +57,37 @@ async function hook () {
50
57
  req.params[key] = val
51
58
  }
52
59
  }
60
+ }, {
61
+ level: 5,
62
+ name: 'waibu:onResponse',
63
+ handler: async function onResponse (req, reply) {
64
+ const { importPkg } = this.app.bajo
65
+ const { get } = this.app.lib._
66
+ const { plain } = this.app.bajo.config.log
67
+ const chalk = await importPkg('bajo:chalk')
68
+ let level = 'info'
69
+ if (reply.statusCode >= 300 && reply.statusCode < 400) level = 'warn'
70
+ else if (reply.statusCode >= 400) level = 'error'
71
+ const ns = get(reply.request, 'routeOptions.config.webApp') ?? this.ns
72
+ const arrow = plain ? '>' : chalk.bold('🡪')
73
+ const mc = methodColor[req.method] ?? 'gray'
74
+ const method = plain ? req.method : chalk[mc](req.method)
75
+ const url = plain ? (':' + req.url) : chalk.gray(':' + req.url)
76
+ let state = plain ? reply.statusCode : chalk.gray(reply.statusCode)
77
+ const sc = stateColor[Math.floor(reply.statusCode / 100)]
78
+ if (!plain && sc) state = chalk[sc](reply.statusCode)
79
+ const elapsed = reply.elapsedTime ?? 0
80
+ let tc = 'red'
81
+ if (elapsed < 1000) tc = 'yellow'
82
+ if (elapsed < 500) tc = 'green'
83
+ const time = plain ? elapsed.toFixed(2) : chalk[tc](elapsed.toFixed(2))
84
+ if (this.config.log.defer) {
85
+ this.reqLog = this.reqLog ?? {}
86
+ if (this.reqLog[req.id] && !this.config.log.noReq) this.app[ns].log.info(this.reqLog[req.id])
87
+ delete this.reqLog[req.id]
88
+ }
89
+ if (!this.config.log.noReply) this.app[ns].log[level]('httpResp%s%s%s%s%s', arrow, method, url, state, time)
90
+ }
53
91
  }, {
54
92
  level: 5,
55
93
  name: 'waibu:onRoute',
@@ -58,6 +58,8 @@ async function buildLocals ({ tpl, params = {}, opts = {} } = {}) {
58
58
  const { req, reply } = opts
59
59
 
60
60
  const _meta = { template: tpl }
61
+ params.page = merge(params.page ?? {}, { ns: req.ns, features: [] })
62
+ params.sidebar = params.sidebar ?? []
61
63
  if (params.error) {
62
64
  if (params.error.statusCode) _meta.statusCode = params.error.statusCode
63
65
  _meta.errorMessage = params.error.message
@@ -66,8 +68,6 @@ async function buildLocals ({ tpl, params = {}, opts = {} } = {}) {
66
68
  if (this.app.bajo.config.env === 'dev') console.log(params.error)
67
69
  }
68
70
  if (!opts.partial) {
69
- params.page = merge(params.page ?? {}, { ns: req.ns, features: [] })
70
- params.sidebar = params.sidebar ?? []
71
71
  merge(_meta, pick(req, ['site', 'user', 'lang', 'darkMode', 'url']))
72
72
  _meta.params = cloneDeep(req.params)
73
73
  _meta.query = cloneDeep(req.query)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu",
3
- "version": "2.15.0",
3
+ "version": "2.15.2",
4
4
  "description": "Web Framework for Bajo",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-05-29
4
+
5
+ - [2.15.1] Bug fix in ```build-locals.js```
6
+ - [2.15.2] Bug fix in ```hook.js```
7
+
3
8
  ## 2026-05-28
4
9
 
5
10
  - [2.15.0] Change hooks to be written in one ```hook.js``` file