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 +1 -2
- package/lib/handle-error.js +1 -1
- package/lib/handle-home.js +10 -12
- package/lib/handle-redirect.js +4 -4
- package/package.json +1 -1
- package/wiki/CHANGES.md +5 -0
package/index.js
CHANGED
|
@@ -76,7 +76,7 @@ async function factory (pkgName) {
|
|
|
76
76
|
* @type {Object}
|
|
77
77
|
*/
|
|
78
78
|
this.config = {
|
|
79
|
-
home:
|
|
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
|
|
package/lib/handle-error.js
CHANGED
|
@@ -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.
|
|
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
|
}
|
package/lib/handle-home.js
CHANGED
|
@@ -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 {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
package/lib/handle-redirect.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
|
|
3
3
|
export function redirect (err = {}, req, reply) {
|
|
4
|
-
if (err.
|
|
5
|
-
else reply.redirect(this.routePath(err.
|
|
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 (
|
|
12
|
-
return redirect.call(me, {
|
|
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
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
|
|