waibu 2.6.0 → 2.7.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 -5
- package/lib/handle-not-found.js +8 -4
- package/lib/webapp-scope/attach-intl.js +4 -0
- package/package.json +1 -1
- package/wiki/CHANGES.md +6 -0
package/index.js
CHANGED
|
@@ -329,15 +329,16 @@ async function factory (pkgName) {
|
|
|
329
329
|
*
|
|
330
330
|
* @method
|
|
331
331
|
* @param {string} prefix
|
|
332
|
+
* @param {boolean} nsOnly - Set ```true``` to return plugin's namespace only
|
|
332
333
|
* @returns {Object}
|
|
333
334
|
*/
|
|
334
|
-
getPluginByPrefix = (prefix) => {
|
|
335
|
+
getPluginByPrefix = (prefix, nsOnly) => {
|
|
335
336
|
const { get, find } = this.app.lib._
|
|
336
|
-
const
|
|
337
|
-
return get(
|
|
337
|
+
const ns = find(this.app.getAllNs(), p => {
|
|
338
|
+
return get(this, `app.${p}.config.waibu.prefix`) === prefix
|
|
338
339
|
})
|
|
339
|
-
|
|
340
|
-
|
|
340
|
+
if (!ns) return
|
|
341
|
+
return nsOnly ? ns : this.app[ns]
|
|
341
342
|
}
|
|
342
343
|
|
|
343
344
|
/**
|
package/lib/handle-not-found.js
CHANGED
|
@@ -10,12 +10,16 @@ export function writeHtml (req, reply, tpl, payload) {
|
|
|
10
10
|
return compiled(payload)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export async function interceptor (
|
|
14
|
-
const { get } = this.app.lib._
|
|
15
|
-
|
|
13
|
+
export async function interceptor (name, err, req, reply) {
|
|
14
|
+
const { get, trim } = this.app.lib._
|
|
15
|
+
let webApp = get(req, 'routeOptions.config.webApp')
|
|
16
|
+
if (!webApp) {
|
|
17
|
+
const [prefix] = trim(req.url, '/').split('/')
|
|
18
|
+
webApp = this.getPluginByPrefix(prefix, true)
|
|
19
|
+
}
|
|
16
20
|
if (webApp) {
|
|
17
21
|
const plugin = this.app[webApp]
|
|
18
|
-
const handler = get(plugin, `
|
|
22
|
+
const handler = get(plugin, `webAppFactory.${name}`)
|
|
19
23
|
if (handler) return await handler.call(plugin, err, req, reply)
|
|
20
24
|
}
|
|
21
25
|
}
|
|
@@ -57,6 +57,10 @@ async function attachIntl (detector = [], req, reply) {
|
|
|
57
57
|
return this.app[defNs].t(text, ...args)
|
|
58
58
|
// return result.replaceAll("'", ''').replaceAll('"', '"')
|
|
59
59
|
}
|
|
60
|
+
req.te = (text, ...args) => {
|
|
61
|
+
args.push({ lang: req.lang })
|
|
62
|
+
return this.app[defNs].te(text, ...args)
|
|
63
|
+
}
|
|
60
64
|
req.format = (value, type = 'auto', opts = {}) => {
|
|
61
65
|
opts.lang = opts.lang ?? req.lang
|
|
62
66
|
const timeZone = get(req, 'site.setting.sumba.timeZone', this.app.bajo.config.intl.format.datetime.timeZone)
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED