waibu 2.6.0 → 2.7.1
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/extend/bajo/intl/en-US.json +3 -1
- package/extend/bajo/intl/id.json +3 -1
- package/index.js +6 -5
- package/lib/handle-error.js +5 -1
- package/lib/handle-not-found.js +19 -7
- package/lib/template/404.html +9 -0
- package/lib/template/500.html +9 -0
- package/lib/webapp-scope/attach-intl.js +4 -0
- package/package.json +1 -1
- package/wiki/CHANGES.md +13 -0
|
@@ -15,5 +15,7 @@
|
|
|
15
15
|
"middlewareDisabled%s": "Middleware '%s' is disabled",
|
|
16
16
|
"httpResp%s%s%s%s%s": "%s %s%s with a %s-status took %sms",
|
|
17
17
|
"httpReq%s%s%s%s": "%s %s%s from IP %s",
|
|
18
|
-
"httpReqExt%s": ", content length: %s"
|
|
18
|
+
"httpReqExt%s": ", content length: %s",
|
|
19
|
+
"internalServerError": "Internal Server Error",
|
|
20
|
+
"pageNotFound": "Page Not Found"
|
|
19
21
|
}
|
package/extend/bajo/intl/id.json
CHANGED
|
@@ -15,5 +15,7 @@
|
|
|
15
15
|
"middlewareDisabled%s": "Middleware '%s' dimatikan",
|
|
16
16
|
"httpResp%s%s%s%s%s": "%s %s:%s dengan status %s selama %sms",
|
|
17
17
|
"httpReq%s%s%s%s": "%s %s:%s dari IP %s",
|
|
18
|
-
"httpReqExt%s": ", panjang konten: %s"
|
|
18
|
+
"httpReqExt%s": ", panjang konten: %s",
|
|
19
|
+
"internalServerError": "Kesalahan Internal Server",
|
|
20
|
+
"pageNotFound": "Halaman Tidak Ditemukan"
|
|
19
21
|
}
|
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-error.js
CHANGED
|
@@ -5,7 +5,11 @@ async function error (err, req, reply) {
|
|
|
5
5
|
this.log.error(err)
|
|
6
6
|
const resp = await interceptor.call(this, 'errorHandler', err, req, reply)
|
|
7
7
|
if (resp) return resp
|
|
8
|
-
|
|
8
|
+
const payload = {
|
|
9
|
+
text: this.app.log.getErrorMessage(err),
|
|
10
|
+
title: req.t('internalServerError')
|
|
11
|
+
}
|
|
12
|
+
return writeHtml.call(this, req, reply, `${this.ns}:/lib/template/500.html`, payload)
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
async function handleError () {
|
package/lib/handle-not-found.js
CHANGED
|
@@ -5,17 +5,26 @@ export function writeHtml (req, reply, tpl, payload) {
|
|
|
5
5
|
reply.header('Content-Type', 'text/html')
|
|
6
6
|
reply.header('Content-Language', req.lang)
|
|
7
7
|
const file = getPluginFile(tpl)
|
|
8
|
-
const content = fs.readFileSync(file)
|
|
8
|
+
const content = fs.readFileSync(file, 'utf8')
|
|
9
9
|
const compiled = template(content)
|
|
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 url = req.url ?? req.raw.url
|
|
18
|
+
const [prefix] = trim(url, '/').split('/')
|
|
19
|
+
webApp = this.getPluginByPrefix(prefix, true)
|
|
20
|
+
}
|
|
21
|
+
if (!webApp) {
|
|
22
|
+
const wa = this.webApps.find(item => item.prefix === '')
|
|
23
|
+
if (wa) webApp = wa.ns
|
|
24
|
+
}
|
|
16
25
|
if (webApp) {
|
|
17
26
|
const plugin = this.app[webApp]
|
|
18
|
-
const handler = get(plugin, `
|
|
27
|
+
const handler = get(plugin, `webAppFactory.${name}`)
|
|
19
28
|
if (handler) return await handler.call(plugin, err, req, reply)
|
|
20
29
|
}
|
|
21
30
|
}
|
|
@@ -55,8 +64,11 @@ export async function notFound (err, req, reply) {
|
|
|
55
64
|
reply.code(404)
|
|
56
65
|
const resp = await interceptor.call(this, 'notFoundHandler', err, req, reply)
|
|
57
66
|
if (resp) return resp
|
|
58
|
-
const
|
|
59
|
-
|
|
67
|
+
const payload = {
|
|
68
|
+
text: req.t('notFound%s%s', req.t('route'), req.url),
|
|
69
|
+
title: req.t('pageNotFound')
|
|
70
|
+
}
|
|
71
|
+
return writeHtml.call(this, req, reply, `${this.ns}:/lib/template/404.html`, payload)
|
|
60
72
|
}
|
|
61
73
|
|
|
62
74
|
async function handleNotFound () {
|
|
@@ -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
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-02-21
|
|
4
|
+
|
|
5
|
+
- [2.7.1] Bug fix on ```errorHandler```
|
|
6
|
+
- [2.7.1] Bug fix on ```notFoundHandler```
|
|
7
|
+
- [2.7.1] Add fallback template for both handlers above
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## 2026-02-20
|
|
11
|
+
|
|
12
|
+
- [2.7.0] Add ```req.te()``` decorator
|
|
13
|
+
- [2.7.0] Bug fix on ```getPluginByPrefix()```
|
|
14
|
+
- [2.7.0] Bug fix on ```notFoundHandler.interceptor()```
|
|
15
|
+
|
|
3
16
|
## 2026-02-18
|
|
4
17
|
|
|
5
18
|
- [2.6.0] Move attribute functions from ```waibu-mpa```
|