waibu 2.9.2 → 2.10.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
@@ -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)
@@ -0,0 +1,21 @@
1
+ async function decorate () {
2
+ const { get } = this.app.lib._
3
+ const { breakNsPath } = this.app.bajo
4
+ const me = this
5
+ this.instance.decorateRequest('lang', null)
6
+ this.instance.decorateRequest('t', () => {})
7
+ this.instance.decorateRequest('format', () => {})
8
+ this.instance.decorateRequest('langDetector', null)
9
+ this.instance.decorateRequest('site', null)
10
+ this.instance.decorateRequest('ns', null)
11
+ this.instance.decorateRequest('getSetting', function (key, defValue) {
12
+ let { ns, path } = breakNsPath(key)
13
+ const paths = path.replaceAll('/', '.').split('.')
14
+ if (paths[0] === '') paths.shift()
15
+ path = paths.join('.')
16
+ const cfgValue = get(me.app, `${ns}.config.${path}`, defValue)
17
+ return get(this, `site.setting.${ns}.${path}`, cfgValue)
18
+ })
19
+ }
20
+
21
+ export default decorate
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu",
3
- "version": "2.9.2",
3
+ "version": "2.10.0",
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-04-11
4
+
5
+ - [2.10.0] Move all decorator to own file ```decorator.js```
6
+ - [2.10.0] Add new decorator ```req.getSetting()```
7
+
3
8
  ## 2026-03-15
4
9
 
5
10
  - [2.9.2] Bug fix missing default ```favicon.png```