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 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 item = find(this.app.waibu.routes, r => {
337
- return get(r, 'config.prefix') === prefix
337
+ const ns = find(this.app.getAllNs(), p => {
338
+ return get(this, `app.${p}.config.waibu.prefix`) === prefix
338
339
  })
339
- const ns = get(item, 'config.ns')
340
- if (ns) return this.app[ns]
340
+ if (!ns) return
341
+ return nsOnly ? ns : this.app[ns]
341
342
  }
342
343
 
343
344
  /**
@@ -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 (err, name, req, reply) {
14
- const { get } = this.app.lib._
15
- const webApp = get(req, 'routeOptions.config.webApp')
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, `waibuFactory.${name}`)
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "Web Framework for Bajo",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-02-20
4
+
5
+ - [2.7.0] Add ```req.te()``` decorator
6
+ - [2.7.0] Bug fix on ```getPluginByPrefix()```
7
+ - [2.7.0] Bug fix on ```notFoundHandler.interceptor()```
8
+
3
9
  ## 2026-02-18
4
10
 
5
11
  - [2.6.0] Move attribute functions from ```waibu-mpa```