waibu-rest-api 2.11.1 → 2.13.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.
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
async function hook () {
|
|
2
|
+
return [{
|
|
3
|
+
level: 9,
|
|
4
|
+
name: 'waibuRestApi:preParsing',
|
|
5
|
+
handler: async function (req, reply) {
|
|
6
|
+
const { importModule } = this.app.bajo
|
|
7
|
+
const attachIntl = await importModule('waibu:/lib/webapp-scope/attach-intl.js')
|
|
8
|
+
await attachIntl.call(this, this.config.intl.detectors, req, reply)
|
|
9
|
+
reply.header('Content-Language', req.lang)
|
|
10
|
+
if (this.config.format.asExt && req.params.format) {
|
|
11
|
+
if (!this.config.format.supported.includes(req.params.format)) {
|
|
12
|
+
throw this.error('unsupportedFormat%s', req.params.format, { statusCode: 406 })
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}, {
|
|
17
|
+
name: 'waibu:afterInit',
|
|
18
|
+
handler: async function () {
|
|
19
|
+
this.app.waibu.config.paramsCharMap[this.config.mapSlash] = '/'
|
|
20
|
+
// this.app.waibu.config.paramsCharMap[this.config.mapDot] = '.'
|
|
21
|
+
}
|
|
22
|
+
}]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default hook
|
package/extend/waibu/boot.js
CHANGED
|
@@ -20,7 +20,7 @@ const boot = {
|
|
|
20
20
|
handler: async function (prefix) {
|
|
21
21
|
const { importPkg, eachPlugins, importModule, runHook } = this.app.bajo
|
|
22
22
|
const { fastGlob } = this.app.lib
|
|
23
|
-
const { getPluginPrefix } = this.app.waibu
|
|
23
|
+
const { getPluginPrefix, isRouteDisabled } = this.app.waibu
|
|
24
24
|
const [bodyParser, accepts] = await importPkg('waibu:@fastify/formbody', 'waibu:@fastify/accepts')
|
|
25
25
|
const routeHook = await importModule('waibu:/lib/webapp-scope/route-hook.js')
|
|
26
26
|
const handleMultipart = await importModule('waibu:/lib/webapp-scope/handle-multipart-body.js')
|
|
@@ -68,11 +68,7 @@ const boot = {
|
|
|
68
68
|
if (!Array.isArray(mods)) mods = [mods]
|
|
69
69
|
for (const mod of mods) {
|
|
70
70
|
const fullPath = appPrefix === '/' ? mod.url : (appPrefix + mod.url)
|
|
71
|
-
|
|
72
|
-
if (await isRouteDisabled.call(this, fullPath, mod.method, me.config.disabled)) {
|
|
73
|
-
this.log.warn('routeDisabled%s%s', `${prefix}${fullPath}`, mod.method)
|
|
74
|
-
continue
|
|
75
|
-
}
|
|
71
|
+
if (isRouteDisabled(`${prefix === '' ? '' : `/${prefix}`}${fullPath}`)) continue
|
|
76
72
|
const rpath = await reroutedPath.call(this, fullPath, me.config.rerouted)
|
|
77
73
|
if (me.config.format.asExt) mod.url = formatExt(mod.url)
|
|
78
74
|
if (rpath) {
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-06-10
|
|
4
|
+
|
|
5
|
+
- [2.13.0] Remove route redirects because now directly handled by ```waibu```
|
|
6
|
+
|
|
7
|
+
## 2026-05-28
|
|
8
|
+
|
|
9
|
+
- [2.12.0] Change hooks to be written in one ```hook.js``` file
|
|
10
|
+
|
|
3
11
|
## 2026-05-22
|
|
4
12
|
|
|
5
13
|
- [2.11.1] Bug fix in ```serve-route.js```
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const waibuRestApiPreParsing = {
|
|
2
|
-
level: 9,
|
|
3
|
-
handler: async function (req, reply) {
|
|
4
|
-
const { importModule } = this.app.bajo
|
|
5
|
-
const attachIntl = await importModule('waibu:/lib/webapp-scope/attach-intl.js')
|
|
6
|
-
await attachIntl.call(this, this.config.intl.detectors, req, reply)
|
|
7
|
-
reply.header('Content-Language', req.lang)
|
|
8
|
-
if (this.config.format.asExt && req.params.format) {
|
|
9
|
-
if (!this.config.format.supported.includes(req.params.format)) {
|
|
10
|
-
throw this.error('unsupportedFormat%s', req.params.format, { statusCode: 406 })
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default waibuRestApiPreParsing
|