waibu-mpa 2.6.0 → 2.6.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/bajoTemplate/template/404.html +14 -0
- package/extend/bajoTemplate/template/500.html +14 -0
- package/extend/waibuStatic/asset/css/default.css +7 -0
- package/lib/error-handler.js +8 -17
- package/lib/not-found-handler.js +8 -4
- package/package.json +1 -1
- package/wiki/CHANGES.md +6 -0
- package/extend/bajoTemplate/partial/404.html +0 -4
- package/extend/bajoTemplate/partial/500.html +0 -8
- package/extend/bajoTemplate/template/_500.html +0 -8
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
5
|
+
<link rel="stylesheet" href="<%= _routePath('waibuMpa.virtual:/purecss/pure-min.css') %>" />
|
|
6
|
+
<link rel="stylesheet" href="<%= _routePath('waibuMpa.asset:/css/default.css') %>" />
|
|
7
|
+
<title><%= _t('pageNotFound') %></title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div class="container-center">
|
|
11
|
+
<p><%= _t('pageNotFound') %></p>
|
|
12
|
+
</div>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
5
|
+
<link rel="stylesheet" href="<%= _routePath('waibuMpa.virtual:/purecss/pure-min.css') %>" />
|
|
6
|
+
<link rel="stylesheet" href="<%= _routePath('waibuMpa.virtual:/purecss/pure-min.css') %>" />
|
|
7
|
+
<title><%= _t('internalServerError') %></title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div class="container-center">
|
|
11
|
+
<%= error.message %>
|
|
12
|
+
</div>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
package/lib/error-handler.js
CHANGED
|
@@ -1,36 +1,27 @@
|
|
|
1
1
|
import notFoundHandler from './not-found-handler.js'
|
|
2
2
|
|
|
3
3
|
async function errorHandler (err, req, reply) {
|
|
4
|
-
const { getPluginFile } = this.app.bajo
|
|
5
4
|
const { fs } = this.app.lib
|
|
6
|
-
const { resolveTemplate } = this.app.bajoTemplate
|
|
7
|
-
const { template } = this.app.lib._
|
|
5
|
+
const { resolveTemplate, compile } = this.app.bajoTemplate
|
|
8
6
|
err.statusCode = err.statusCode ?? 500
|
|
9
7
|
reply.code(err.statusCode)
|
|
8
|
+
reply.header('Content-Type', `text/html; charset=${this.config.page.charset}`)
|
|
9
|
+
reply.header('Content-Language', req.lang)
|
|
10
10
|
|
|
11
11
|
if (err.message === '_notFound' || err.statusCode === 404) {
|
|
12
12
|
return await notFoundHandler.call(this, err, req, reply)
|
|
13
13
|
}
|
|
14
14
|
if (err.noContent) return ''
|
|
15
15
|
const ns = err.ns ?? this.ns
|
|
16
|
-
let result
|
|
16
|
+
// let result
|
|
17
17
|
let tpl = `${ns}.template:/${err.statusCode ?? 500}.html`
|
|
18
18
|
try {
|
|
19
|
-
|
|
19
|
+
tpl = resolveTemplate(tpl)
|
|
20
20
|
} catch (err) {
|
|
21
|
-
tpl = `${this.ns}.template:/500.html`
|
|
21
|
+
tpl = resolveTemplate(`${this.ns}.template:/500.html`)
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} catch (err) {
|
|
26
|
-
// only getting here when there is error on view rendering
|
|
27
|
-
console.error(err)
|
|
28
|
-
const file = getPluginFile(`${this.ns}:/extend/bajoTemplate/template/_500.html`)
|
|
29
|
-
const content = fs.readFileSync(file)
|
|
30
|
-
const compiled = template(content)
|
|
31
|
-
result = compiled({ error: err })
|
|
32
|
-
}
|
|
33
|
-
return result
|
|
23
|
+
const content = fs.readFileSync(tpl.file, 'utf8')
|
|
24
|
+
return await compile(content, { error: err })
|
|
34
25
|
}
|
|
35
26
|
|
|
36
27
|
export default errorHandler
|
package/lib/not-found-handler.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
async function notFoundHandler (err, req, reply) {
|
|
2
2
|
const welcome = req.url.split('?')[0] === '/'
|
|
3
|
-
const {
|
|
3
|
+
const { fs } = this.app.lib
|
|
4
|
+
const { resolveTemplate, compile } = this.app.bajoTemplate
|
|
4
5
|
const msg = req.t('routeNotFound%s%s', req.url, req.method)
|
|
5
6
|
const error = err ?? this.error(msg)
|
|
6
7
|
if (err) error.message = msg
|
|
7
8
|
error.statusCode = 404
|
|
8
9
|
reply.code(404)
|
|
10
|
+
reply.header('Content-Type', `text/html; charset=${this.config.page.charset}`)
|
|
11
|
+
reply.header('Content-Language', req.lang)
|
|
9
12
|
if (error.noContent) return ''
|
|
10
13
|
const ns = error.ns ?? this.ns
|
|
11
14
|
let tpl = welcome ? `${this.ns}.template:/welcome.html` : `${ns}.template:/404.html`
|
|
12
15
|
try {
|
|
13
|
-
|
|
16
|
+
tpl = resolveTemplate(tpl)
|
|
14
17
|
} catch (err) {
|
|
15
|
-
tpl = `${this.ns}.template:/404.html`
|
|
18
|
+
tpl = resolveTemplate(`${this.ns}.template:/404.html`)
|
|
16
19
|
}
|
|
17
|
-
|
|
20
|
+
const content = fs.readFileSync(tpl.file, 'utf8')
|
|
21
|
+
return await compile(content, { error: err })
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
export default notFoundHandler
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED