waibu 2.18.1 → 2.19.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/index.js CHANGED
@@ -76,7 +76,7 @@ async function factory (pkgName) {
76
76
  * @type {Object}
77
77
  */
78
78
  this.config = {
79
- home: undefined,
79
+ home: {},
80
80
  server: {
81
81
  host: '127.0.0.1',
82
82
  port: 17845
@@ -165,7 +165,6 @@ async function factory (pkgName) {
165
165
  init = async () => {
166
166
  const { isString } = this.app.lib._
167
167
  if (isString(this.config.log.disable)) this.config.log.disable = [this.config.log.disable]
168
- if (this.config.home === '/') this.config.home = false
169
168
  await collectRoutePathHandlers.call(this)
170
169
  }
171
170
 
@@ -16,7 +16,7 @@ async function handleError () {
16
16
  const me = this
17
17
  this.instance.setErrorHandler(async function (err, req, reply) {
18
18
  if (err.message === '_notFound' || err.statusCode === 404) return await notFound.call(me, err, req, reply)
19
- if (err.message === '_redirect' && err.redirect) return redirect.call(me, err, req, reply)
19
+ if (err.message === '_redirect' && err.path) return redirect.call(me, err, req, reply)
20
20
  return await error.call(me, err, req, reply)
21
21
  })
22
22
  }
@@ -1,17 +1,15 @@
1
1
  async function handleHome () {
2
- const { callHandler } = this.app.bajo
3
2
  const { defaultsDeep } = this.app.lib.aneka
4
- const { isString, pick } = this.app.lib._
5
- const config = this.getConfig()
6
- if (config.home) {
7
- if (isString(config.home)) config.home = { path: config.home }
8
- if (config.home.pathHandler) config.home.path = await callHandler(config.home.pathHandler)
9
- await this.instance.get('/', async function (req, reply) {
10
- if (!config.home.forward) return reply.redirectTo(config.home.path)
11
- const opts = defaultsDeep(pick(req, ['params', 'query']), pick(config.home, ['params', 'query']))
12
- return reply.forwardTo(config.home.path, opts)
13
- })
14
- }
3
+ const { pick } = this.app.lib._
4
+ const me = this
5
+ this.instance.get('/', async function (req, reply) {
6
+ const home = req.getSetting('waibu:home', {})
7
+ if (!home.path) throw me.error('_notFound')
8
+ home.options = home.options ?? {}
9
+ if (!home.forward) return reply.redirectTo(home.path, home.options)
10
+ const opts = defaultsDeep(pick(req, ['params', 'query']), pick(home, ['params', 'query']))
11
+ return reply.forwardTo(home.path, opts)
12
+ })
15
13
  }
16
14
 
17
15
  export default handleHome
@@ -1,15 +1,15 @@
1
1
  import path from 'path'
2
2
 
3
3
  export function redirect (err = {}, req, reply) {
4
- if (err.redirect.startsWith('http') || path.isAbsolute(err.redirect)) reply.redirect(err.redirect)
5
- else reply.redirect(this.routePath(err.redirect, err.options))
4
+ if (err.path.startsWith('http') || path.isAbsolute(err.path)) reply.redirect(err.path)
5
+ else reply.redirect(this.routePath(err.path, err.options), err.redirectCode)
6
6
  return reply
7
7
  }
8
8
 
9
9
  async function handleRedirect (options) {
10
10
  const me = this
11
- this.instance.decorateReply('redirectTo', function (url, options = {}) {
12
- return redirect.call(me, { redirect: url, options }, null, this)
11
+ this.instance.decorateReply('redirectTo', function (path, options = {}) {
12
+ return redirect.call(me, { path, options }, null, this)
13
13
  })
14
14
  }
15
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu",
3
- "version": "2.18.1",
3
+ "version": "2.19.1",
4
4
  "description": "Web Framework for Bajo",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -4,6 +4,11 @@
4
4
 
5
5
  - [2.18.1] Bug fix in ```routePath()```
6
6
  - [2.18.1] Bug fix in ```req.getSetting()```
7
+ - [2.19.0] Add feature to read ```config.home``` from ```req.getSetting()```
8
+ - [2.19.0] Simplify ```config.home``` to only accept object
9
+ - [2.19.0] Add ```options.redirectCode``` to ```reply.redirectTo()```
10
+ - [2.19.0] Home route config now read from ```req.getSetting()```
11
+ - [2.19.1] Bug fix in ```handle-error.js```
7
12
 
8
13
  ## 2026-06-12
9
14