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 +6 -6
- package/lib/decorate.js +1 -5
- package/lib/handle-home.js +10 -12
- package/lib/handle-redirect.js +4 -4
- package/package.json +1 -1
- package/wiki/CHANGES.md +9 -0
package/index.js
CHANGED
|
@@ -76,7 +76,7 @@ async function factory (pkgName) {
|
|
|
76
76
|
* @type {Object}
|
|
77
77
|
*/
|
|
78
78
|
this.config = {
|
|
79
|
-
home:
|
|
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)
|
|
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
|
-
|
|
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
|
|
package/lib/handle-home.js
CHANGED
|
@@ -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 {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
package/lib/handle-redirect.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
|
|
3
3
|
export function redirect (err = {}, req, reply) {
|
|
4
|
-
if (err.
|
|
5
|
-
else reply.redirect(this.routePath(err.
|
|
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 (
|
|
12
|
-
return redirect.call(me, {
|
|
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
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
|