waibu 2.18.0 → 2.19.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.
package/index.js CHANGED
@@ -76,7 +76,7 @@ async function factory (pkgName) {
76
76
  * @type {Object}
77
77
  */
78
78
  this.config = {
79
- home: undefined,
79
+ home: {},
80
80
  server: {
81
81
  host: '127.0.0.1',
82
82
  port: 17845
@@ -165,7 +165,6 @@ async function factory (pkgName) {
165
165
  init = async () => {
166
166
  const { isString } = this.app.lib._
167
167
  if (isString(this.config.log.disable)) this.config.log.disable = [this.config.log.disable]
168
- if (this.config.home === '/') this.config.home = false
169
168
  await collectRoutePathHandlers.call(this)
170
169
  }
171
170
 
@@ -485,7 +484,7 @@ async function factory (pkgName) {
485
484
  if (['%', '.', '/', '?', '#'].includes(name[0]) || name.slice(1, 2) === ':') info.path = name
486
485
  else if (['~'].includes(name[0])) info.path = name.slice(1)
487
486
  else {
488
- info = breakNsPath(name)
487
+ info = breakNsPath(name, false)
489
488
  }
490
489
  if (info.path.slice(0, 2) === './') info.path = info.path.slice(2)
491
490
  if (this.routePathHandlers[info.subNs]) return (neg ? '!' : '') + this.routePathHandlers[info.subNs].handler(name, options)
@@ -603,9 +602,10 @@ async function factory (pkgName) {
603
602
  const paths = path.replaceAll('/', '.').split('.')
604
603
  if (paths[0] === '') paths.shift()
605
604
  path = paths.join('.')
606
- const cfgValue = get(this.app, `${ns}.config.${path}`)
607
- const reqValue = get(req, `site.setting.${ns}.${path}`)
608
- if (isPlainObject(cfgValue) || isArray(cfgValue)) return defaultsDeep({}, reqValue, cfgValue, defValue)
605
+ const cfgValue = get(this.app, `${ns}.config.${path}`, defValue)
606
+ const reqValue = get(req, `site.setting.${ns}.${path}`, defValue)
607
+ if (isPlainObject(cfgValue)) return defaultsDeep({}, reqValue, cfgValue)
608
+ if (isArray(cfgValue)) return reqValue.length > 0 ? reqValue : cfgValue
609
609
  return reqValue ?? cfgValue ?? defValue
610
610
  }
611
611
 
package/lib/decorate.js CHANGED
@@ -1,6 +1,4 @@
1
1
  async function decorate () {
2
- const { isPlainObject, isArray } = this.app.lib._
3
- const { defaultsDeep } = this.app.lib.aneka
4
2
  const me = this
5
3
  this.instance.decorateRequest('lang', null)
6
4
  this.instance.decorateRequest('t', () => {})
@@ -10,9 +8,7 @@ async function decorate () {
10
8
  this.instance.decorateRequest('site', null)
11
9
  this.instance.decorateRequest('ns', null)
12
10
  this.instance.decorateRequest('getSetting', function (key, defValue) {
13
- const value = me.app.waibu.getSetting(key, { req: this })
14
- if (isPlainObject(value) || isArray(value)) return defaultsDeep({}, value, defValue)
15
- return value ?? defValue
11
+ return me.app.waibu.getSetting(key, { req: this, defValue })
16
12
  })
17
13
  }
18
14
 
@@ -1,17 +1,15 @@
1
1
  async function handleHome () {
2
- const { callHandler } = this.app.bajo
3
2
  const { defaultsDeep } = this.app.lib.aneka
4
- const { isString, pick } = this.app.lib._
5
- const config = this.getConfig()
6
- if (config.home) {
7
- if (isString(config.home)) config.home = { path: config.home }
8
- if (config.home.pathHandler) config.home.path = await callHandler(config.home.pathHandler)
9
- await this.instance.get('/', async function (req, reply) {
10
- if (!config.home.forward) return reply.redirectTo(config.home.path)
11
- const opts = defaultsDeep(pick(req, ['params', 'query']), pick(config.home, ['params', 'query']))
12
- return reply.forwardTo(config.home.path, opts)
13
- })
14
- }
3
+ const { pick } = this.app.lib._
4
+ const me = this
5
+ this.instance.get('/', async function (req, reply) {
6
+ const home = req.getSetting('waibu:home', {})
7
+ if (!home.path) throw me.error('_notFound')
8
+ home.options = home.options ?? {}
9
+ if (!home.forward) return reply.redirectTo(home.path, home.options)
10
+ const opts = defaultsDeep(pick(req, ['params', 'query']), pick(home, ['params', 'query']))
11
+ return reply.forwardTo(home.path, opts)
12
+ })
15
13
  }
16
14
 
17
15
  export default handleHome
@@ -1,15 +1,15 @@
1
1
  import path from 'path'
2
2
 
3
3
  export function redirect (err = {}, req, reply) {
4
- if (err.redirect.startsWith('http') || path.isAbsolute(err.redirect)) reply.redirect(err.redirect)
5
- else reply.redirect(this.routePath(err.redirect, err.options))
4
+ if (err.path.startsWith('http') || path.isAbsolute(err.path)) reply.redirect(err.path)
5
+ else reply.redirect(this.routePath(err.path, err.options), err.redirectCode)
6
6
  return reply
7
7
  }
8
8
 
9
9
  async function handleRedirect (options) {
10
10
  const me = this
11
- this.instance.decorateReply('redirectTo', function (url, options = {}) {
12
- return redirect.call(me, { redirect: url, options }, null, this)
11
+ this.instance.decorateReply('redirectTo', function (path, options = {}) {
12
+ return redirect.call(me, { path, 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.18.0",
3
+ "version": "2.19.0",
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-19
4
+
5
+ - [2.18.1] Bug fix in ```routePath()```
6
+ - [2.18.1] Bug fix in ```req.getSetting()```
7
+ - [2.19.0] Add feature to read ```config.home``` from ```req.getSetting()```
8
+ - [2.19.0] Simplify ```config.home``` to only accept object
9
+ - [2.19.0] Add ```options.redirectCode``` to ```reply.redirectTo()```
10
+ - [2.19.0] Home route config now read from ```req.getSetting()```
11
+
3
12
  ## 2026-06-12
4
13
 
5
14
  - [2.18.0] Necessary updates to ```bajo@2.18.0``` specs