waibu 2.7.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.
@@ -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
  }
@@ -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
  }
@@ -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
- return writeHtml.call(this, req, reply, `${this.ns}:/extend/bajoTemplate/template/500.html`, { text: this.app.log.getErrorMessage(err) })
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 () {
@@ -5,7 +5,7 @@ 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
  }
@@ -14,9 +14,14 @@ export async function interceptor (name, err, req, reply) {
14
14
  const { get, trim } = this.app.lib._
15
15
  let webApp = get(req, 'routeOptions.config.webApp')
16
16
  if (!webApp) {
17
- const [prefix] = trim(req.url, '/').split('/')
17
+ const url = req.url ?? req.raw.url
18
+ const [prefix] = trim(url, '/').split('/')
18
19
  webApp = this.getPluginByPrefix(prefix, true)
19
20
  }
21
+ if (!webApp) {
22
+ const wa = this.webApps.find(item => item.prefix === '')
23
+ if (wa) webApp = wa.ns
24
+ }
20
25
  if (webApp) {
21
26
  const plugin = this.app[webApp]
22
27
  const handler = get(plugin, `webAppFactory.${name}`)
@@ -59,8 +64,11 @@ export async function notFound (err, req, reply) {
59
64
  reply.code(404)
60
65
  const resp = await interceptor.call(this, 'notFoundHandler', err, req, reply)
61
66
  if (resp) return resp
62
- const text = req.t('notFound%s%s', req.t('route'), req.url)
63
- return writeHtml.call(this, req, reply, `${this.ns}:/extend/bajoTemplate/template/400.html`, { text })
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)
64
72
  }
65
73
 
66
74
  async function handleNotFound () {
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= title %></title>
5
+ </head>
6
+ <body>
7
+ <%= text %>
8
+ </body>
9
+ </html>
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= title %></title>
5
+ </head>
6
+ <body>
7
+ <%= text %>
8
+ </body>
9
+ </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu",
3
- "version": "2.7.0",
3
+ "version": "2.7.1",
4
4
  "description": "Web Framework for Bajo",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,12 @@
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
+
3
10
  ## 2026-02-20
4
11
 
5
12
  - [2.7.0] Add ```req.te()``` decorator