waibu-rest-api 2.13.0 → 2.14.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/extend/bajo/hook.js +1 -1
- package/extend/waibu/boot.js +11 -25
- package/index.js +568 -79
- package/lib/config.js +90 -0
- package/lib/{doc-schema/model.js → helper.js} +161 -166
- package/package.json +1 -1
- package/wiki/CHANGES.md +4 -0
- package/lib/decorate.js +0 -4
- package/lib/doc-schema/description.js +0 -13
- package/lib/doc-schema/for-find.js +0 -17
- package/lib/doc-schema/general.js +0 -79
- package/lib/doc-schema/lib.js +0 -8
- package/lib/doc-schema/params.js +0 -28
- package/lib/doc-schema/qs.js +0 -15
- package/lib/error.js +0 -19
- package/lib/handle-response/xml.js +0 -36
- package/lib/handle-response.js +0 -21
- package/lib/not-found.js +0 -11
- package/lib/route-by-model-builder.js +0 -99
- package/lib/route-by-verb.js +0 -63
- package/lib/serve-route.js +0 -23
- package/lib/sub-app.js +0 -15
package/extend/bajo/hook.js
CHANGED
|
@@ -4,7 +4,7 @@ async function hook () {
|
|
|
4
4
|
name: 'waibuRestApi:preParsing',
|
|
5
5
|
handler: async function (req, reply) {
|
|
6
6
|
const { importModule } = this.app.bajo
|
|
7
|
-
const attachIntl = await importModule('waibu:/lib/webapp
|
|
7
|
+
const { attachIntl } = await importModule('waibu:/lib/webapp.js', { asDefaultImport: false })
|
|
8
8
|
await attachIntl.call(this, this.config.intl.detectors, req, reply)
|
|
9
9
|
reply.header('Content-Language', req.lang)
|
|
10
10
|
if (this.config.format.asExt && req.params.format) {
|
package/extend/waibu/boot.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
|
-
import decorate from '../../lib/decorate.js'
|
|
3
|
-
import routeByModelBuilder from '../../lib/route-by-model-builder.js'
|
|
4
|
-
import routeByVerb from '../../lib/route-by-verb.js'
|
|
5
|
-
import notFoundHandler from '../../lib/not-found.js'
|
|
6
|
-
import errorHandler from '../../lib/error.js'
|
|
7
|
-
import subApp from '../../lib/sub-app.js'
|
|
8
|
-
import handleResponse from '../../lib/handle-response.js'
|
|
9
|
-
|
|
10
|
-
const routeActions = { routeByModelBuilder, routeByVerb }
|
|
11
2
|
|
|
12
3
|
function formatExt (item) {
|
|
13
4
|
return item + '.:format'
|
|
@@ -15,26 +6,19 @@ function formatExt (item) {
|
|
|
15
6
|
|
|
16
7
|
const boot = {
|
|
17
8
|
level: 10,
|
|
18
|
-
notFoundHandler,
|
|
19
|
-
errorHandler,
|
|
20
9
|
handler: async function (prefix) {
|
|
21
10
|
const { importPkg, eachPlugins, importModule, runHook } = this.app.bajo
|
|
22
11
|
const { fastGlob } = this.app.lib
|
|
23
12
|
const { getPluginPrefix, isRouteDisabled } = this.app.waibu
|
|
24
13
|
const [bodyParser, accepts] = await importPkg('waibu:@fastify/formbody', 'waibu:@fastify/accepts')
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const handleHelmet = await importModule('waibu:/lib/webapp-scope/handle-helmet.js')
|
|
30
|
-
const handleCompress = await importModule('waibu:/lib/webapp-scope/handle-compress.js')
|
|
31
|
-
const handleRateLimit = await importModule('waibu:/lib/webapp-scope/handle-rate-limit.js')
|
|
32
|
-
const reroutedPath = await importModule('waibu:/lib/webapp-scope/rerouted-path.js')
|
|
14
|
+
const {
|
|
15
|
+
routeHook, handleMultipartBody, handleXmlBody, handleCors, handleHelmet, handleCompress,
|
|
16
|
+
handleRateLimit, reroutedPath
|
|
17
|
+
} = await importModule('waibu:/lib/webapp.js', { asDefaultImport: false })
|
|
33
18
|
|
|
34
19
|
const pathPrefix = `${this.ns}/route`
|
|
35
20
|
await this.docSchemaGeneral()
|
|
36
21
|
await routeHook.call(this, this.ns)
|
|
37
|
-
await decorate.call(this)
|
|
38
22
|
if (this.config.format.supported.includes('xml')) {
|
|
39
23
|
await handleXmlBody.call(this, this.config.format.xml.bodyParser)
|
|
40
24
|
}
|
|
@@ -43,9 +27,9 @@ const boot = {
|
|
|
43
27
|
await handleRateLimit.call(this, this.config.rateLimit)
|
|
44
28
|
await handleCors.call(this, this.config.cors)
|
|
45
29
|
await handleHelmet.call(this, this.config.helmet)
|
|
46
|
-
await
|
|
30
|
+
await handleMultipartBody.call(this, this.config.multipart)
|
|
47
31
|
await handleCompress.call(this, this.config.compress)
|
|
48
|
-
await
|
|
32
|
+
await this._handleResponse()
|
|
49
33
|
await runHook(`${this.ns}:beforeCreateRoutes`, this.webAppCtx)
|
|
50
34
|
const actions = ['find', 'get', 'create', 'update', 'remove']
|
|
51
35
|
if (this.config.enablePatch) actions.push('replace')
|
|
@@ -63,8 +47,10 @@ const boot = {
|
|
|
63
47
|
await me.webAppCtx.register(async (appCtx) => {
|
|
64
48
|
for (const file of files) {
|
|
65
49
|
const base = path.basename(file, path.extname(file))
|
|
66
|
-
|
|
67
|
-
|
|
50
|
+
let mods
|
|
51
|
+
if (base === 'model-builder') mods = await me._routeByModelBuilder({ file, dir, pathPrefix, ns, parent: me.ns })
|
|
52
|
+
else mods = await me._routeByVerb({ file, appCtx, dir, pathPrefix, ns, alias, parent: me.ns })
|
|
53
|
+
|
|
68
54
|
if (!Array.isArray(mods)) mods = [mods]
|
|
69
55
|
for (const mod of mods) {
|
|
70
56
|
const fullPath = appPrefix === '/' ? mod.url : (appPrefix + mod.url)
|
|
@@ -82,7 +68,7 @@ const boot = {
|
|
|
82
68
|
}, { prefix: appPrefix })
|
|
83
69
|
})
|
|
84
70
|
await runHook(`${this.ns}:afterCreateRoutes`, this.webAppCtx)
|
|
85
|
-
await
|
|
71
|
+
await this._handleSubApp()
|
|
86
72
|
}
|
|
87
73
|
}
|
|
88
74
|
|