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 CHANGED
@@ -27,6 +27,10 @@
27
27
  "title": "My Website",
28
28
  "orgName": "My Organization"
29
29
  },
30
+ "cors": {},
31
+ "compress": {},
32
+ "helmet": {},
33
+ "rateLimit": {},
30
34
  "multipart": {
31
35
  "attachFieldsToBody": true,
32
36
  "limits": {
@@ -1,5 +1,5 @@
1
1
  async function onClose () {
2
- this.log.info('Server is closed')
2
+ this.log.info('serverIs%s', this.print.write('closedL'))
3
3
  }
4
4
 
5
5
  export default onClose
@@ -1,5 +1,5 @@
1
1
  async function onReady () {
2
- this.log.info('Server is ready!')
2
+ this.log.info('serverIs%s', this.print.write('readyL'))
3
3
  }
4
4
 
5
5
  export default onReady
@@ -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
- "[%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": ""
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
  }
@@ -1,5 +1,5 @@
1
1
  function notFound (name, options) {
2
- throw this.error('notFound', { path: name })
2
+ throw this.error('_notFound', { path: name })
3
3
  }
4
4
 
5
5
  export default notFound
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('Plugin prefix \'%s\' conflic between \'%s\' and \'%s\'', m.prefix, prefixes[m.prefix][0], prefixes[m.prefix][1])
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('All %s routes are disabled by config', m.ns)
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('Boot app: %s', m.ns)
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  async function xmlBodyParser (ctx, opts = {}) {
4
4
  if (!this.app.bajoExtra) {
5
- this.log.warn('Can\'t parse XML body unless package \'%s\' is loaded first', 'bajo-extra')
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('Loaded routes')
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
- return this.app[defNs].print.write(text, req.lang, ...args)
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
- return this.app.bajo.format(value, type, req.lang, opts)
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' && !['notfound', 'redirect'].includes(err.message.toLowerCase())) console.error(err)
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.toLowerCase() === 'notfound' || err.statusCode === 404) {
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
- if (!options) return
5
- await ctx.register(compress, options)
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
- if (!options) return
5
- await ctx.register(cors, options)
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
- if (!options) return
5
- await ctx.register(helmet, options)
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(this.name)}/upload`
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
- const opts = defaultsDeep(options, this.config.multipart)
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
- if (!options) return
6
- await ctx.register(rateLimit, cloneDeep(options))
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "Web Framework for Bajo",
5
5
  "main": "index.js",
6
6
  "scripts": {