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 +2 -6
- package/lib/decorate.js +21 -0
- package/package.json +1 -1
- package/wiki/CHANGES.md +5 -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)
|
package/lib/decorate.js
ADDED
|
@@ -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