waibu 2.11.4 → 2.12.0
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 +6 -4
- package/package.json +1 -1
- package/wiki/CHANGES.md +5 -0
package/index.js
CHANGED
|
@@ -449,12 +449,13 @@ async function factory (pkgName) {
|
|
|
449
449
|
/**
|
|
450
450
|
* Get route path by route's name:
|
|
451
451
|
* - If it is a ```mailto:``` or ```tel:``` url, it returns as is
|
|
452
|
+
* - If it starts with ```:/```, name will be prefixed with its ```ns``` automatically
|
|
452
453
|
* - If it is a ns based name, it will be parsed first
|
|
453
454
|
*
|
|
454
455
|
* @method
|
|
455
456
|
* @param {string} name
|
|
456
457
|
* @param {Object} [options={}] - Options object
|
|
457
|
-
* @param {string} [options.
|
|
458
|
+
* @param {string} [options.ns=waibu] - Base namespace
|
|
458
459
|
* @param {boolean} [options.guessHost] - If true, guest host if host is not set
|
|
459
460
|
* @param {Object} [options.query={}] - Query string's object. If provided, it will be added to returned value
|
|
460
461
|
* @param {Object} [options.params={}] - Parameter object. If provided, it will be merged to returned value
|
|
@@ -465,12 +466,13 @@ async function factory (pkgName) {
|
|
|
465
466
|
const { defaultsDeep } = this.app.lib.aneka
|
|
466
467
|
const { isEmpty, get, trimEnd, trimStart } = this.app.lib._
|
|
467
468
|
const { breakNsPath } = this.app.bajo
|
|
468
|
-
const { query = {},
|
|
469
|
+
const { query = {}, ns = this.ns, params = {}, guessHost, defaults = {}, uriEncoded } = options
|
|
469
470
|
|
|
470
|
-
const plugin = getPlugin(
|
|
471
|
+
const plugin = getPlugin(ns)
|
|
471
472
|
const cfg = plugin.config ?? {}
|
|
472
473
|
let info = {}
|
|
473
474
|
if (name.startsWith('mailto:') || name.startsWith('tel:')) return name
|
|
475
|
+
if (name.slice(0, 2) === ':/') name = ns + name
|
|
474
476
|
if (['%', '.', '/', '?', '#'].includes(name[0]) || name.slice(1, 2) === ':') info.path = name
|
|
475
477
|
else if (['~'].includes(name[0])) info.path = name.slice(1)
|
|
476
478
|
else {
|
|
@@ -491,7 +493,7 @@ async function factory (pkgName) {
|
|
|
491
493
|
let url = info.path
|
|
492
494
|
const langDetector = get(cfg, 'intl.detectors', [])
|
|
493
495
|
if (info.ns) url = trimEnd(langDetector.includes('path') ? `/${params.lang ?? ''}${this.routeDir(info.ns)}${info.path}` : `${this.routeDir(info.ns)}${info.path}`, '/')
|
|
494
|
-
if (
|
|
496
|
+
if (uriEncoded) url = url.split('/').map(u => encodeURI(u)).join('/')
|
|
495
497
|
info.qs = defaultsDeep({}, query, info.qs)
|
|
496
498
|
if (!isEmpty(info.qs)) url += '?' + this.qs.stringify(info.qs)
|
|
497
499
|
if (!url.startsWith('http') && guessHost) url = `http://${this.config.server.host}:${this.config.server.port}/${trimStart(url, '/')}`
|
package/package.json
CHANGED