waibu 1.0.10 → 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": {
@@ -10,5 +10,6 @@
10
10
  "routeDisabled%s%s": "Route %s (%s) is disabled",
11
11
  "rerouted%s%s": "Rerouted %s -> %s",
12
12
  "bootSubApp%s": "Boot sub app: %s",
13
- "routeNotFound%s%s": "Route '%s (%s)' not found"
13
+ "routeNotFound%s%s": "Route '%s (%s)' not found",
14
+ "middlewareDisabled%s": "Middleware '%s' is disabled"
14
15
  }
package/bajo/intl/id.json CHANGED
@@ -10,5 +10,6 @@
10
10
  "routeDisabled%s%s": "Jalur %s (%s) dimatikan",
11
11
  "rerouted%s%s": "Jalur dipindahkan %s -> %s",
12
12
  "bootSubApp%s": "Boot sub app: %s",
13
- "routeNotFound%s%s": "Jalur '%s (%s)' tidak ditemukan"
13
+ "routeNotFound%s%s": "Jalur '%s (%s)' tidak ditemukan",
14
+ "middlewareDisabled%s": "Middleware '%s' dimatikan"
14
15
  }
@@ -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.10",
3
+ "version": "1.0.11",
4
4
  "description": "Web Framework for Bajo",
5
5
  "main": "index.js",
6
6
  "scripts": {