waibu 2.16.0 → 2.16.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.
@@ -54,15 +54,16 @@ const omitted = ['createdAt', 'updatedAt', '_immutable']
54
54
 
55
55
  async function buildLocals ({ tpl, params = {}, opts = {} } = {}) {
56
56
  const { runHook } = this.app.bajo
57
- const { set, merge, pick, get, isEmpty, find, cloneDeep, omit } = this.app.lib._
57
+ const { set, merge, pick, get, isEmpty, find, cloneDeep, omit, isFunction } = this.app.lib._
58
58
  const { req, reply } = opts
59
59
 
60
60
  const _meta = { template: tpl }
61
61
  params.page = merge(params.page ?? {}, { ns: req.ns, features: [] })
62
62
  params.sidebar = params.sidebar ?? []
63
63
  if (params.error) {
64
- if (params.error.statusCode) _meta.statusCode = params.error.statusCode
65
- _meta.errorMessage = params.error.message
64
+ for (const ns of this.app.getAllNs()) {
65
+ if (isFunction(this.app[ns].sanitizeError)) this.app[ns].sanitizeError(params.error)
66
+ }
66
67
  if (params.error.ns) params.page.ns = params.error.ns
67
68
  this.log.error('error%s', params.error.message)
68
69
  if (this.app.bajo.config.env === 'dev') console.log(params.error)
@@ -13,10 +13,12 @@ export function writeHtml (req, reply, tpl, payload) {
13
13
  export async function interceptor (name, err, req, reply) {
14
14
  const { get, trim } = this.app.lib._
15
15
  let webApp = get(req, 'routeOptions.config.webApp')
16
+ const all = this.webApps.map(item => item.ns)
16
17
  if (!webApp) {
17
18
  const url = req.url ?? req.raw.url
18
19
  const [prefix] = trim(url, '/').split('/')
19
- webApp = this.getPluginByPrefix(prefix, true)
20
+ const ns = this.getPluginByPrefix(prefix, true)
21
+ if (all.includes(ns)) webApp = ns
20
22
  }
21
23
  if (!webApp) {
22
24
  const wa = this.webApps.find(item => item.prefix === '')
@@ -30,27 +32,42 @@ export async function interceptor (name, err, req, reply) {
30
32
  }
31
33
 
32
34
  function redirSvc (req) {
33
- const { trim, find, get } = this.app.lib._
35
+ const { trim, get } = this.app.lib._
34
36
  const { outmatch } = this.app.lib
35
- let match = false
36
- let [prefix, ...args] = trim(req.url, '/').split('/')
37
- args = '/' + args.join('/')
38
- let plugin = find(this.app.getAllNs(), p => {
39
- return get(this, `app.${p}.config.waibu.prefix`) === prefix
40
- })
41
- if (!plugin) {
42
- plugin = 'main'
43
- args = `/${prefix}`
44
- }
45
- const items = get(this, `app.${plugin}.config.waibuMpa.redirect`, {})
46
- for (const k in items) {
47
- const isMatch = outmatch(k)
48
- if (isMatch(args)) {
49
- match = items[k]
50
- break
37
+
38
+ const matchRoute = (path, items) => {
39
+ let match = false
40
+ for (const k in items) {
41
+ const isMatch = outmatch(k)
42
+ if (isMatch(path)) {
43
+ match = items[k]
44
+ const parts = path.split('/')
45
+ const patterns = k.split('/')
46
+ for (const idx in patterns) {
47
+ if (patterns[idx] === '*') match = match.replace(`{${idx}}`, parts[idx])
48
+ }
49
+ break
50
+ }
51
51
  }
52
+ return match
53
+ }
54
+
55
+ const [prefix, subPrefix, ...args] = trim(req.url.split('?')[0].split('#')[0], '/').split('/')
56
+ let plugin = this.getPluginByPrefix(prefix)
57
+ const subPlugin = this.getPluginByPrefix(subPrefix)
58
+ if (!plugin && !subPlugin) plugin = this.app.main
59
+ let route = false
60
+ if (plugin && subPlugin) {
61
+ const items = get(this, `app.${subPlugin.ns}.config.waibuMpa.redirectSubRoute.${plugin.ns}`, {})
62
+ route = matchRoute(`/${args.join('/')}`, items)
63
+ if (route) return route
64
+ }
65
+ if (plugin) {
66
+ const items = get(this, `app.${plugin.ns}.config.waibuMpa.redirect`, {})
67
+ route = matchRoute(subPrefix ? `/${subPrefix}/${args.join('/')}` : '/', items)
68
+ if (route) return route
52
69
  }
53
- return match
70
+ return route
54
71
  }
55
72
 
56
73
  export async function notFound (err, req, reply) {
@@ -9,7 +9,7 @@ export function redirect (err = {}, req, reply) {
9
9
  async function handleRedirect (options) {
10
10
  const me = this
11
11
  this.instance.decorateReply('redirectTo', function (url, options = {}) {
12
- return redirect.call(me, { redirect: url, options }, null, this, url, options)
12
+ return redirect.call(me, { redirect: url, options }, null, this)
13
13
  })
14
14
  }
15
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu",
3
- "version": "2.16.0",
3
+ "version": "2.16.2",
4
4
  "description": "Web Framework for Bajo",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-06-05
4
+
5
+ - [2.16.2] Bug fix in ```build-locals.js```
6
+ - [2.16.2] Bug fix in ```handle-not-found.js```
7
+
8
+ ## 2026-06-03
9
+
10
+ - [2.16.1] Bug fix in ```handle-redirect.js```
11
+
3
12
  ## 2026-05-30
4
13
 
5
14
  - [2.16.0] Change ```config.log.[noReq|noReply]``` to array ```config.log.disable``` with possible values: ```request``` and ```response```. Defaults to empty values