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.
@@ -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>
@@ -0,0 +1,7 @@
1
+ .container-center {
2
+ display: flex;
3
+ justify-content: center;
4
+ align-items: center;
5
+ height: 100vh;
6
+ width: 100%;
7
+ }
@@ -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
- await resolveTemplate(tpl)
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
- try {
24
- result = await reply.view(tpl, { error: err })
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
@@ -1,20 +1,24 @@
1
1
  async function notFoundHandler (err, req, reply) {
2
2
  const welcome = req.url.split('?')[0] === '/'
3
- const { resolveTemplate } = this.app.bajoTemplate
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
- await resolveTemplate(tpl)
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
- if (reply.view) return await reply.view(tpl, { error })
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-mpa",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
4
4
  "description": "MPA support for Waibu Framework",
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-21
4
+
5
+ - [2.6.1] Bug fix on ```errorHandler```
6
+ - [2.6.1] Bug fix on ```notFoundHandler```
7
+ - [2.6.1] Add fallback template for both handlers above
8
+
3
9
  ## 2026-02-18
4
10
 
5
11
  - [2.6.0] Add auto trashing old session
@@ -1,4 +0,0 @@
1
- <c:div text="align:center">
2
- <c:heading type="6-display" t:content="Not Found" />
3
- <c:p t:content="404Message" />
4
- </c:div>
@@ -1,8 +0,0 @@
1
- <c:div text="align:center">
2
- <c:heading type="6-display" t:content="Internal Server Error" />
3
- <% if (_meta.env === 'dev') { %>
4
- <%= _meta.errorMessage %>
5
- <% } else { %>
6
- <c:t>500Message</c:t>
7
- <% } %>
8
- </c:div>
@@ -1,8 +0,0 @@
1
- <html>
2
- <head>
3
- <title>System Error</title>
4
- </head>
5
- <body>
6
- Error Message: <%= error.message %>
7
- </body>
8
- </html>