waibu 1.0.9 → 1.0.11
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/config.json +4 -0
- package/bajo/hook/on-close.js +1 -1
- package/bajo/hook/on-ready.js +1 -1
- package/bajo/intl/en-US.json +15 -0
- package/bajo/intl/id.json +13 -44
- package/bajo/method/not-found.js +1 -1
- package/lib/app.js +3 -3
- package/lib/handle-xml-body.js +1 -1
- package/lib/log-routes.js +1 -1
- package/lib/webapp-scope/attach-intl.js +5 -3
- package/lib/webapp-scope/error-handler.js +2 -2
- package/lib/webapp-scope/handle-compress.js +4 -2
- package/lib/webapp-scope/handle-cors.js +4 -2
- package/lib/webapp-scope/handle-helmet.js +4 -2
- package/lib/webapp-scope/handle-multipart-body.js +3 -2
- package/lib/webapp-scope/handle-rate-limit.js +4 -2
- package/package.json +1 -1
package/bajo/config.json
CHANGED
package/bajo/hook/on-close.js
CHANGED
package/bajo/hook/on-ready.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
"middlewareDisabled%s": "Middleware '%s' is disabled"
|
|
15
|
+
}
|
package/bajo/intl/id.json
CHANGED
|
@@ -1,46 +1,15 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
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": ""
|
|
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
|
+
"middlewareDisabled%s": "Middleware '%s' dimatikan"
|
|
46
15
|
}
|
package/bajo/method/not-found.js
CHANGED
package/lib/app.js
CHANGED
|
@@ -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
|
})
|
|
@@ -53,10 +53,12 @@ async function attachIntl (detector = [], req, reply) {
|
|
|
53
53
|
detect.call(this, detector, req, reply)
|
|
54
54
|
const defNs = get(req, 'routeOptions.config.ns', this.name)
|
|
55
55
|
req.t = (text, ...args) => {
|
|
56
|
-
|
|
56
|
+
args.push({ lang: req.lang })
|
|
57
|
+
return this.app[defNs].print.write(text, ...args)
|
|
57
58
|
}
|
|
58
|
-
req.format = (value, type = 'auto', opts) => {
|
|
59
|
-
|
|
59
|
+
req.format = (value, type = 'auto', opts = {}) => {
|
|
60
|
+
opts.lang = opts.lang ?? req.lang
|
|
61
|
+
return this.app.bajo.format(value, type, opts)
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
64
|
|
|
@@ -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
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import compress from '@fastify/compress'
|
|
2
2
|
|
|
3
3
|
async function handleCompress (ctx, options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const { defaultsDeep } = this.app.bajo
|
|
5
|
+
if (options === false) return this.log.warn('middlewareDisabled%s', 'compress')
|
|
6
|
+
const opts = defaultsDeep(options, this.app.waibu.config.compress)
|
|
7
|
+
await ctx.register(compress, opts)
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
export default handleCompress
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import cors from '@fastify/cors'
|
|
2
2
|
|
|
3
3
|
async function handleCors (ctx, options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const { defaultsDeep } = this.app.bajo
|
|
5
|
+
if (options === false) return this.log.warn('middlewareDisabled%s', 'cors')
|
|
6
|
+
const opts = defaultsDeep(options, this.app.waibu.config.cors)
|
|
7
|
+
await ctx.register(cors, opts)
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
export default handleCors
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import helmet from '@fastify/helmet'
|
|
2
2
|
|
|
3
3
|
async function handleHelmet (ctx, options = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const { defaultsDeep } = this.app.bajo
|
|
5
|
+
if (options === false) return this.log.warn('middlewareDisabled%s', 'helmet')
|
|
6
|
+
const opts = defaultsDeep(options, this.app.waibu.config.helmet)
|
|
7
|
+
await ctx.register(helmet, opts)
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
export default handleHelmet
|
|
@@ -7,7 +7,7 @@ const pump = promisify(pipeline)
|
|
|
7
7
|
async function onFileHandler () {
|
|
8
8
|
const { getPluginDataDir } = this.app.bajo
|
|
9
9
|
const { fs } = this.app.bajo.lib
|
|
10
|
-
const dir = `${getPluginDataDir(
|
|
10
|
+
const dir = `${getPluginDataDir('waibu')}/upload`
|
|
11
11
|
return async function (part) {
|
|
12
12
|
// 'this' is the fastify context here
|
|
13
13
|
const filePath = `${dir}/${this.id}/${part.fieldname}@${part.filename}`
|
|
@@ -20,7 +20,8 @@ async function handleMultipartBody (ctx, options = {}) {
|
|
|
20
20
|
const { defaultsDeep, importPkg, isSet } = this.app.bajo
|
|
21
21
|
const { isArray, map, trim, isPlainObject, isEmpty } = this.app.bajo.lib._
|
|
22
22
|
const parseVar = await importPkg('dotenv-parse-variables')
|
|
23
|
-
|
|
23
|
+
if (options === false) return this.log.warn('middlewareDisabled%s', 'multipart')
|
|
24
|
+
const opts = defaultsDeep(options, this.app.waibu.config.multipart)
|
|
24
25
|
const onFile = await onFileHandler.call(this)
|
|
25
26
|
opts.onFile = onFile
|
|
26
27
|
await ctx.register(multipart, opts)
|
|
@@ -2,8 +2,10 @@ import rateLimit from '@fastify/rate-limit'
|
|
|
2
2
|
|
|
3
3
|
async function handleRateLimit (ctx, options = {}) {
|
|
4
4
|
const { cloneDeep } = this.app.bajo.lib._
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const { defaultsDeep } = this.app.bajo
|
|
6
|
+
if (options === false) return this.log.warn('middlewareDisabled%s', 'rateLimit')
|
|
7
|
+
const opts = defaultsDeep(options, this.app.waibu.config.rateLimit)
|
|
8
|
+
await ctx.register(rateLimit, cloneDeep(opts))
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
export default handleRateLimit
|