waibu 2.9.2 → 2.11.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 +13 -6
- package/lib/decorate.js +14 -0
- package/package.json +1 -1
- package/wiki/CHANGES.md +10 -0
package/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import handleError from './lib/handle-error.js'
|
|
|
12
12
|
import handleNotFound from './lib/handle-not-found.js'
|
|
13
13
|
import handleHome from './lib/handle-home.js'
|
|
14
14
|
import queryString from 'query-string'
|
|
15
|
+
import decorate from './lib/decorate.js'
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* @typedef TEscapeChars
|
|
@@ -181,13 +182,8 @@ async function factory (pkgName) {
|
|
|
181
182
|
cfg.factory.querystringParser = str => this.qs.parse(str)
|
|
182
183
|
|
|
183
184
|
this.instance = fastify(cfg.factory)
|
|
184
|
-
this.instance.decorateRequest('lang', null)
|
|
185
|
-
this.instance.decorateRequest('t', () => {})
|
|
186
|
-
this.instance.decorateRequest('format', () => {})
|
|
187
|
-
this.instance.decorateRequest('langDetector', null)
|
|
188
|
-
this.instance.decorateRequest('site', null)
|
|
189
|
-
this.instance.decorateRequest('ns', null)
|
|
190
185
|
this.routes = this.routes || []
|
|
186
|
+
await decorate.call(this)
|
|
191
187
|
await runHook('waibu:afterCreateContext', this.instance)
|
|
192
188
|
await this.instance.register(sensible)
|
|
193
189
|
if (cfg.underPressure) await this.instance.register(underPressure)
|
|
@@ -583,6 +579,17 @@ async function factory (pkgName) {
|
|
|
583
579
|
})
|
|
584
580
|
return result.join(delimiter)
|
|
585
581
|
}
|
|
582
|
+
|
|
583
|
+
getSetting = (key, { defValue, req = {} } = {}) => {
|
|
584
|
+
const { breakNsPath } = this.app.bajo
|
|
585
|
+
const { get } = this.app.lib._
|
|
586
|
+
let { ns, path } = breakNsPath(key)
|
|
587
|
+
const paths = path.replaceAll('/', '.').split('.')
|
|
588
|
+
if (paths[0] === '') paths.shift()
|
|
589
|
+
path = paths.join('.')
|
|
590
|
+
const cfgValue = get(this.app, `${ns}.config.${path}`, defValue)
|
|
591
|
+
return get(req, `site.setting.${ns}.${path}`, cfgValue)
|
|
592
|
+
}
|
|
586
593
|
}
|
|
587
594
|
|
|
588
595
|
return Waibu
|
package/lib/decorate.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
async function decorate () {
|
|
2
|
+
const me = this
|
|
3
|
+
this.instance.decorateRequest('lang', null)
|
|
4
|
+
this.instance.decorateRequest('t', () => {})
|
|
5
|
+
this.instance.decorateRequest('format', () => {})
|
|
6
|
+
this.instance.decorateRequest('langDetector', null)
|
|
7
|
+
this.instance.decorateRequest('site', null)
|
|
8
|
+
this.instance.decorateRequest('ns', null)
|
|
9
|
+
this.instance.decorateRequest('getSetting', function (key, defValue) {
|
|
10
|
+
return me.app.waibu.getSetting(key, { defValue, req: this })
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default decorate
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-04-13
|
|
4
|
+
|
|
5
|
+
- [2.11.0] Add ```getSetting()```
|
|
6
|
+
- [2.11.0] ```req.getSetting()``` now accept setting ```site.setting``` too
|
|
7
|
+
|
|
8
|
+
## 2026-04-11
|
|
9
|
+
|
|
10
|
+
- [2.10.0] Move all decorator to own file ```decorator.js```
|
|
11
|
+
- [2.10.0] Add new decorator ```req.getSetting()```
|
|
12
|
+
|
|
3
13
|
## 2026-03-15
|
|
4
14
|
|
|
5
15
|
- [2.9.2] Bug fix missing default ```favicon.png```
|