waibu-mpa 2.18.1 → 2.19.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/extend/bajoTemplate/template/500.html +1 -1
- package/lib/build-routes.js +13 -19
- package/lib/class/widget/page-end.js +11 -10
- package/lib/error-handler.js +9 -2
- package/package.json +1 -1
- package/wiki/CHANGES.md +10 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
5
5
|
<link rel="stylesheet" href="<%= _routePath('waibuMpa.virtual:/purecss/pure-min.css') %>" />
|
|
6
|
-
<link rel="stylesheet" href="<%= _routePath('waibuMpa.
|
|
6
|
+
<link rel="stylesheet" href="<%= _routePath('waibuMpa.asset:/css/default.css') %>" />
|
|
7
7
|
<title><%= _t('internalServerError') %></title>
|
|
8
8
|
</head>
|
|
9
9
|
<body>
|
package/lib/build-routes.js
CHANGED
|
@@ -72,14 +72,11 @@ export async function build ({ files, pathPrefix, dir, ns, cfg, parent, urlPrefi
|
|
|
72
72
|
|
|
73
73
|
async function addRoutes ({ appPrefix, prefix, mods, appCtx, cfg }) {
|
|
74
74
|
const { importModule } = this.app.bajo
|
|
75
|
-
const isRouteDisabled =
|
|
75
|
+
const { isRouteDisabled } = this.app.waibu
|
|
76
76
|
const reroutedPath = await importModule('waibu:/lib/webapp-scope/rerouted-path.js')
|
|
77
77
|
for (const mod of mods) {
|
|
78
|
-
const fullPath = `/${appPrefix}${mod.url}`
|
|
79
|
-
if (
|
|
80
|
-
this.log.warn('routeDisabled%s%s', `${prefix}${fullPath}`, mod.method)
|
|
81
|
-
continue
|
|
82
|
-
}
|
|
78
|
+
const fullPath = appPrefix === '' ? mod.url : `/${appPrefix}${mod.url}`
|
|
79
|
+
if (isRouteDisabled(`${prefix === '' ? '' : `/${prefix}`}${fullPath}`)) continue
|
|
83
80
|
const rpath = await reroutedPath.call(this, fullPath, cfg.rerouted)
|
|
84
81
|
if (rpath) {
|
|
85
82
|
this.log.warn('rerouted%s%s', `${prefix}${fullPath}`, `${prefix}${rpath}`)
|
|
@@ -128,22 +125,19 @@ async function buildRoutes (prefix) {
|
|
|
128
125
|
subRoutes = groupBy(subRoutes, 'ns')
|
|
129
126
|
for (const k in subRoutes) {
|
|
130
127
|
const items = subRoutes[k]
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const appCtx = appCtxs[ns]
|
|
134
|
-
if (!appCtx) throw this.error('cantHaveSubroutesWithoutContext%s', ns)
|
|
135
|
-
let appPrefix = getPluginPrefix(sns)
|
|
136
|
-
if (sns === me.ns || (sns === me.app.mainNs && cfg.mountMainAsRoot)) appPrefix = ''
|
|
137
|
-
await runHook(`${me.ns}.${k}:beforeBuildSubRoutes`, appCtx, appPrefix)
|
|
128
|
+
const appCtx = appCtxs[k]
|
|
129
|
+
if (!appCtx) throw this.error('cantHaveSubroutesWithoutContext%s', k)
|
|
138
130
|
for (const item of items) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const
|
|
143
|
-
const
|
|
131
|
+
let appPrefix = getPluginPrefix(k)
|
|
132
|
+
if (item.sns === me.ns || (item.sns === me.app.mainNs && cfg.mountMainAsRoot)) appPrefix = ''
|
|
133
|
+
await runHook(`${me.ns}.${k}:beforeBuildSubRoutes`, appCtx, appPrefix)
|
|
134
|
+
const scope = this.app[item.sns]
|
|
135
|
+
const pathPrefix = `waibuMpa/extend/${item.ns}/route/`
|
|
136
|
+
const urlPrefix = getPluginPrefix(item.sns)
|
|
137
|
+
const mods = await build.call(scope, { appCtx, files: [item.file], pathPrefix, dir: item.dir, ns: item.ns, cfg, parent: me.ns, urlPrefix, subRoute: item.sns })
|
|
144
138
|
await addRoutes.call(me, { appPrefix, prefix, mods, appCtx, cfg })
|
|
139
|
+
await runHook(`${me.ns}.${k}:afterBuildSubRoutes`, appCtx, appPrefix)
|
|
145
140
|
}
|
|
146
|
-
await runHook(`${me.ns}.${k}:afterBuildSubRoutes`, appCtx, appPrefix)
|
|
147
141
|
}
|
|
148
142
|
}
|
|
149
143
|
|
|
@@ -11,7 +11,7 @@ async function pageEndFactory () {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
build = async () => {
|
|
14
|
-
const { get } = this.app.lib._
|
|
14
|
+
const { get, isEmpty } = this.app.lib._
|
|
15
15
|
const { groupAttrs } = this.app.waibuMpa
|
|
16
16
|
const { widget, locals, req } = this.component
|
|
17
17
|
|
|
@@ -23,24 +23,25 @@ async function pageEndFactory () {
|
|
|
23
23
|
let tc = ''
|
|
24
24
|
if (!this.params.attr.noToastContainer && widget.toastStack && widget.toast) {
|
|
25
25
|
const toasts = []
|
|
26
|
-
if (get(locals, 'error') && get(locals, '_meta.flash
|
|
26
|
+
if (get(locals, 'error') && !isEmpty(get(locals, '_meta.flash'))) {
|
|
27
27
|
const details = get(locals.error, 'details', [])
|
|
28
|
+
const attr = {
|
|
29
|
+
border: 'side:all width:0',
|
|
30
|
+
text: 'background:danger'
|
|
31
|
+
}
|
|
28
32
|
if (details.length > 0) {
|
|
33
|
+
attr.title = req.t(locals.error.title ?? locals.error.orgMessage ?? locals.error.message)
|
|
29
34
|
const list = [`<ul class="m-0 ${details.length === 1 ? 'list-unstyled' : ''}">`]
|
|
30
35
|
for (const d of details) {
|
|
31
36
|
const field = req.t(`field.${d.field}`)
|
|
32
|
-
list.push(`<li><strong>${field}:</strong> ${d.error}</li>`)
|
|
37
|
+
list.push(`<li><strong>${field}:</strong> ${req.t(d.error)}</li>`)
|
|
33
38
|
}
|
|
34
39
|
list.push('</ul>')
|
|
35
|
-
const attr = {
|
|
36
|
-
border: 'side:all width:0',
|
|
37
|
-
text: 'background:danger',
|
|
38
|
-
title: req.t(locals.error.orgMessage ?? locals.error.message)
|
|
39
|
-
}
|
|
40
40
|
toasts.push(await this.component.buildTag({ tag: 'toast', attr, html: list.join('\n') }))
|
|
41
41
|
} else if (!(locals._meta.statusCode === 404 || locals._meta.statusCode >= 500)) {
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
if (locals.error.title) attr.title = req.t(locals.error.title)
|
|
43
|
+
attr.noHide = true
|
|
44
|
+
toasts.push(await this.component.buildTag({ tag: 'toast', attr, html: req.t(locals.error.orgMessage ?? locals.error.message) }))
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
const notifications = get(locals, '_meta.flash.notify', [])
|
package/lib/error-handler.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import notFoundHandler from './not-found-handler.js'
|
|
2
2
|
|
|
3
3
|
async function errorHandler (err, req, reply) {
|
|
4
|
-
const { resolveTemplate } = this.app.bajoTemplate
|
|
4
|
+
const { resolveTemplate, compile } = this.app.bajoTemplate
|
|
5
|
+
const { fs } = this.app.lib
|
|
5
6
|
err.statusCode = err.statusCode ?? 500
|
|
6
7
|
reply.code(err.statusCode)
|
|
7
8
|
reply.header('Content-Type', `text/html; charset=${this.config.page.charset}`)
|
|
@@ -19,7 +20,13 @@ async function errorHandler (err, req, reply) {
|
|
|
19
20
|
} catch (err) {
|
|
20
21
|
tpl = `${this.ns}.template:/500.html`
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
try {
|
|
24
|
+
return await reply.view(tpl, { error: err }, { noFlash: true })
|
|
25
|
+
} catch (err) {
|
|
26
|
+
// only going here if something happened in reply.view
|
|
27
|
+
const content = fs.readFileSync(resolveTemplate(tpl).file, 'utf8')
|
|
28
|
+
return await compile(content, { error: err })
|
|
29
|
+
}
|
|
23
30
|
}
|
|
24
31
|
|
|
25
32
|
export default errorHandler
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-06-10
|
|
4
|
+
|
|
5
|
+
- [2.19.0] Remove route redirects because now directly handled by ```waibu```
|
|
6
|
+
- [2.19.0] Bug fix in ```page-end``` widget
|
|
7
|
+
|
|
8
|
+
## 2026-06-05
|
|
9
|
+
|
|
10
|
+
- [2.18.2] Bug fix in ```error-handler.js```
|
|
11
|
+
- [2.18.2] Bug fix in ```page-end``` widget
|
|
12
|
+
|
|
3
13
|
## 2026-06-04
|
|
4
14
|
|
|
5
15
|
- [2.18.1] Bug fix in ```component.buildTag()```
|