waibu 1.0.8 → 1.0.10
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/bajo/hook/on-close.js +1 -1
- package/bajo/hook/on-ready.js +1 -1
- package/bajo/intl/en-US.json +14 -0
- package/bajo/intl/id.json +14 -0
- package/bajo/method/not-found.js +1 -1
- package/bajo/method/route-path.js +1 -1
- package/bajo/start.js +1 -1
- package/lib/app.js +4 -4
- package/lib/handle-xml-body.js +1 -1
- package/lib/log-routes.js +1 -1
- package/lib/webapp-scope/{attach-i18n.js → attach-intl.js} +10 -16
- package/lib/webapp-scope/error-handler.js +2 -2
- package/package.json +1 -1
- package/bajoI18N/resource/id.json +0 -46
package/bajo/hook/on-close.js
CHANGED
package/bajo/hook/on-ready.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"pluginPrefixConflic%s%s%s": "Plugin prefix '%s' conflict between '%s' and '%s'",
|
|
3
|
+
"serverIs%s": "Server is %s",
|
|
4
|
+
"closedL": "closed",
|
|
5
|
+
"readyL": "ready",
|
|
6
|
+
"allRoutesConfigDisabled%s": "All '%s' routes are disabled by config",
|
|
7
|
+
"bootApp%s": "Boot app: %s",
|
|
8
|
+
"cantParseXmlBodyWithout%s": "Can't parse XML body unless package '%s' is loaded first",
|
|
9
|
+
"routesL": "routes",
|
|
10
|
+
"routeDisabled%s%s": "Route %s (%s) is disabled",
|
|
11
|
+
"rerouted%s%s": "Rerouted %s -> %s",
|
|
12
|
+
"bootSubApp%s": "Boot sub app: %s",
|
|
13
|
+
"routeNotFound%s%s": "Route '%s (%s)' not found"
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"pluginPrefixConflic%s%s%s": "Ada konflik di prefiks '%s' antara '%s' dan '%s'",
|
|
3
|
+
"serverIs%s": "Server %s",
|
|
4
|
+
"closedL": "tertutup",
|
|
5
|
+
"readyL": "siap sedia",
|
|
6
|
+
"allRoutesConfigDisabled%s": "Semua jalur '%s' dimatikan via konfigurasi",
|
|
7
|
+
"bootApp%s": "Jalankan aplikasi: %s",
|
|
8
|
+
"cantParseXmlBodyWithout%s": "Tidak bisa memparse bodi XML sebelum paket '%s' dimuat terlebih dahulu",
|
|
9
|
+
"routesL": "jalur",
|
|
10
|
+
"routeDisabled%s%s": "Jalur %s (%s) dimatikan",
|
|
11
|
+
"rerouted%s%s": "Jalur dipindahkan %s -> %s",
|
|
12
|
+
"bootSubApp%s": "Boot sub app: %s",
|
|
13
|
+
"routeNotFound%s%s": "Jalur '%s (%s)' tidak ditemukan"
|
|
14
|
+
}
|
package/bajo/method/not-found.js
CHANGED
|
@@ -20,7 +20,7 @@ function routePath (name = '', { query = {}, base = 'waibuMpa', params = {}, gue
|
|
|
20
20
|
return p[0] === ':' && params[p.slice(1)] ? params[p.slice(1)] : p
|
|
21
21
|
}).join('/')
|
|
22
22
|
let url = info.path
|
|
23
|
-
const langDetector = get(cfg, '
|
|
23
|
+
const langDetector = get(cfg, 'intl.detectors', [])
|
|
24
24
|
if (info.ns) url = trimEnd(langDetector.includes('path') ? `/${params.lang ?? ''}${this.routeDir(info.ns)}${info.path}` : `${this.routeDir(info.ns)}${info.path}`, '/')
|
|
25
25
|
info.qs = defaultsDeep({}, query, info.qs)
|
|
26
26
|
if (!isEmpty(info.qs)) url += '?' + this.qs.stringify(info.qs)
|
package/bajo/start.js
CHANGED
|
@@ -22,8 +22,8 @@ async function start () {
|
|
|
22
22
|
|
|
23
23
|
const instance = fastify(cfg.factory)
|
|
24
24
|
instance.decorateRequest('lang', null)
|
|
25
|
-
instance.decorateRequest('i18n', null)
|
|
26
25
|
instance.decorateRequest('t', () => {})
|
|
26
|
+
instance.decorateRequest('format', () => {})
|
|
27
27
|
instance.decorateRequest('langDetector', null)
|
|
28
28
|
instance.decorateRequest('site', null)
|
|
29
29
|
instance.decorateRequest('ns', null)
|
package/lib/app.js
CHANGED
|
@@ -9,7 +9,7 @@ export async function collect (glob = 'boot.js', baseNs) {
|
|
|
9
9
|
await eachPlugins(async function ({ config, file, ns, alias }) {
|
|
10
10
|
const mod = await importModule(file, { asHandler: true })
|
|
11
11
|
mod.prefix = get(config, 'waibu.prefix', alias)
|
|
12
|
-
if (get(config, '
|
|
12
|
+
if (get(config, 'intl.detectors', []).includes('path')) mod.prefix = `/:lang${mod.prefix}`
|
|
13
13
|
mod.ns = ns
|
|
14
14
|
mod.alias = alias
|
|
15
15
|
mods.push(mod)
|
|
@@ -18,7 +18,7 @@ export async function collect (glob = 'boot.js', baseNs) {
|
|
|
18
18
|
mods.forEach(m => {
|
|
19
19
|
if (!prefixes[m.prefix]) prefixes[m.prefix] = []
|
|
20
20
|
prefixes[m.prefix].push(m.plugin)
|
|
21
|
-
if (prefixes[m.prefix].length > 1) this.fatal('
|
|
21
|
+
if (prefixes[m.prefix].length > 1) this.fatal('pluginPrefixConflic%s%s%s', m.prefix, prefixes[m.prefix][0], prefixes[m.prefix][1])
|
|
22
22
|
})
|
|
23
23
|
return orderBy(mods, ['level'])
|
|
24
24
|
}
|
|
@@ -30,11 +30,11 @@ export async function boot () {
|
|
|
30
30
|
for (const m of mods) {
|
|
31
31
|
const disabled = this.app[m.ns].config.disabled
|
|
32
32
|
if (Array.isArray(disabled) && disabled.length === 1 && ['*', 'all'].includes(disabled[0])) {
|
|
33
|
-
this.log.warn('
|
|
33
|
+
this.log.warn('allRoutesConfigDisabled%s', m.ns)
|
|
34
34
|
continue
|
|
35
35
|
}
|
|
36
36
|
await runHook(`${this.name}.${m.ns}:beforeAppBoot`)
|
|
37
|
-
this.log.debug('
|
|
37
|
+
this.log.debug('bootApp%s', m.ns)
|
|
38
38
|
await this.instance.register(async (ctx) => {
|
|
39
39
|
const plugin = this.app[m.ns]
|
|
40
40
|
plugin.instance = ctx
|
package/lib/handle-xml-body.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
async function xmlBodyParser (ctx, opts = {}) {
|
|
4
4
|
if (!this.app.bajoExtra) {
|
|
5
|
-
this.log.warn('
|
|
5
|
+
this.log.warn('cantParseXmlBodyWithout%s', 'bajo-extra')
|
|
6
6
|
return
|
|
7
7
|
}
|
|
8
8
|
const { importPkg } = this.app.bajo
|
package/lib/log-routes.js
CHANGED
|
@@ -10,7 +10,7 @@ function printRoutes () {
|
|
|
10
10
|
}
|
|
11
11
|
})
|
|
12
12
|
items = orderBy(items, ['url'])
|
|
13
|
-
this.log.debug('
|
|
13
|
+
this.log.debug('loaded%s', this.print.write('routesL'))
|
|
14
14
|
items.forEach(item => {
|
|
15
15
|
this.log.debug('- %s (%s)', item.url, item.methods.join('|'))
|
|
16
16
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function detect (detector = [], req, reply) {
|
|
2
2
|
const { get, map, trim, orderBy } = this.app.bajo.lib._
|
|
3
|
-
const supported = get(this, 'app.
|
|
4
|
-
const defLang = get(this, 'app.
|
|
3
|
+
const supported = get(this, 'app.bajo.config.intl.supported', [this.app.bajo.config.lang])
|
|
4
|
+
const defLang = get(this, 'app.bajo.config.intl.fallback', this.app.bajo.config.lang)
|
|
5
5
|
let lang = null
|
|
6
6
|
// by route path
|
|
7
7
|
if (detector.includes('path')) {
|
|
@@ -48,24 +48,18 @@ function detect (detector = [], req, reply) {
|
|
|
48
48
|
req.lang = lang ?? defLang
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
async function
|
|
52
|
-
if (!this.app.bajoI18N) return
|
|
53
|
-
const { importModule } = this.app.bajo
|
|
51
|
+
async function attachIntl (detector = [], req, reply) {
|
|
54
52
|
const { get } = this.app.bajo.lib._
|
|
55
|
-
const translate = await importModule('bajo:/boot/lib/translate.js')
|
|
56
53
|
detect.call(this, detector, req, reply)
|
|
57
54
|
const defNs = get(req, 'routeOptions.config.ns', this.name)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
req.t = (...args) => {
|
|
62
|
-
// console.log(args)
|
|
63
|
-
// const defNs = get(req, 'routeOptions.config.ns', this.name)
|
|
64
|
-
return translate.call(this.app[defNs], req.i18n, ...args)
|
|
55
|
+
req.t = (text, ...args) => {
|
|
56
|
+
args.push({ lang: req.lang })
|
|
57
|
+
return this.app[defNs].print.write(text, ...args)
|
|
65
58
|
}
|
|
66
|
-
req.format = (value, type = 'auto', opts) => {
|
|
67
|
-
|
|
59
|
+
req.format = (value, type = 'auto', opts = {}) => {
|
|
60
|
+
opts.lang = opts.lang ?? req.lang
|
|
61
|
+
return this.app.bajo.format(value, type, opts)
|
|
68
62
|
}
|
|
69
63
|
}
|
|
70
64
|
|
|
71
|
-
export default
|
|
65
|
+
export default attachIntl
|
|
@@ -6,9 +6,9 @@ async function errorHandler (ctx, extHandler) {
|
|
|
6
6
|
reply.send(err.print)
|
|
7
7
|
return
|
|
8
8
|
}
|
|
9
|
-
if (me.app.bajo.config.log.level === 'trace' && !['
|
|
9
|
+
if (me.app.bajo.config.log.level === 'trace' && !['_notFound', '_redirect'].includes(err.message.toLowerCase())) console.error(err)
|
|
10
10
|
if (extHandler) return await extHandler.call(me, err, req, reply, ctx)
|
|
11
|
-
if (err.message
|
|
11
|
+
if (err.message === '_notFound' || err.statusCode === 404) {
|
|
12
12
|
reply.code(err.statusCode)
|
|
13
13
|
return
|
|
14
14
|
}
|
package/package.json
CHANGED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"[%s] Server is closed": "[%s] Penyelia telah tertutup",
|
|
3
|
-
"[%s] Server is ready!": "[%s] Penyelia telah siap!",
|
|
4
|
-
"Route '%s (%s)' not found": "Rute '%s (%s)' tidak ditemukan",
|
|
5
|
-
"Bad Request": "",
|
|
6
|
-
"Unauthorized": "Tidak Terautentikasi",
|
|
7
|
-
"Payment Required": "Pembayaran Disyaratkan",
|
|
8
|
-
"Forbidden": "Dilarang",
|
|
9
|
-
"Not Found": "Tidak Ditemukan",
|
|
10
|
-
"Method Not Allowed": "Metode Tidak Diperkenankan",
|
|
11
|
-
"Not Acceptable": "Tidak Bisa Diterima",
|
|
12
|
-
"Proxy Authentication Required": "",
|
|
13
|
-
"Request Timeout": "",
|
|
14
|
-
"Conflict": "",
|
|
15
|
-
"Gone": "",
|
|
16
|
-
"Length Required": "",
|
|
17
|
-
"Precondition Failed": "",
|
|
18
|
-
"Payload Too Large": "",
|
|
19
|
-
"URI Too Long": "",
|
|
20
|
-
"Unsupported Media Type": "",
|
|
21
|
-
"Range Not Satisfiable": "",
|
|
22
|
-
"Expectation Failed": "",
|
|
23
|
-
"Im A Teapot": "",
|
|
24
|
-
"Misdirected Request": "",
|
|
25
|
-
"Unprocessable Entity": "",
|
|
26
|
-
"Locked": "",
|
|
27
|
-
"Failed Dependency": "",
|
|
28
|
-
"Too Early": "",
|
|
29
|
-
"Upgrade Required": "",
|
|
30
|
-
"Precondition Required": "",
|
|
31
|
-
"Too Many Requests": "",
|
|
32
|
-
"Request Header Fields Too Large": "",
|
|
33
|
-
"Unavailable For Legal Reasons": "",
|
|
34
|
-
"Internal Server Error": "Kesalahan Internal Server",
|
|
35
|
-
"Not Implemented": "",
|
|
36
|
-
"Bad Gateway": "",
|
|
37
|
-
"Service Unavailable": "",
|
|
38
|
-
"Gateway Timeout": "",
|
|
39
|
-
"HTTP Version Not Supported": "",
|
|
40
|
-
"Variant Also Negotiates": "",
|
|
41
|
-
"Insufficient Storage": "",
|
|
42
|
-
"Loop Detected": "",
|
|
43
|
-
"Bandwidth Limit Exceeded": "",
|
|
44
|
-
"Not Extended": "",
|
|
45
|
-
"Network Authentication Require": ""
|
|
46
|
-
}
|