waibu 1.2.12 → 2.0.1
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/.github/FUNDING.yml +13 -0
- package/.github/workflows/repo-lockdown.yml +24 -0
- package/.jsdoc.conf.json +45 -0
- package/LICENSE +1 -1
- package/README.md +40 -7
- package/config-prod.json +1 -1
- package/docs/Waibu.html +3 -0
- package/docs/data/search.json +1 -0
- package/docs/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/global.html +3 -0
- package/docs/index.html +3 -0
- package/docs/index.js.html +566 -0
- package/docs/scripts/core.js +726 -0
- package/docs/scripts/core.min.js +23 -0
- package/docs/scripts/resize.js +90 -0
- package/docs/scripts/search.js +265 -0
- package/docs/scripts/search.min.js +6 -0
- package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
- package/docs/scripts/third-party/fuse.js +9 -0
- package/docs/scripts/third-party/hljs-line-num-original.js +369 -0
- package/docs/scripts/third-party/hljs-line-num.js +1 -0
- package/docs/scripts/third-party/hljs-original.js +5171 -0
- package/docs/scripts/third-party/hljs.js +1 -0
- package/docs/scripts/third-party/popper.js +5 -0
- package/docs/scripts/third-party/tippy.js +1 -0
- package/docs/scripts/third-party/tocbot.js +672 -0
- package/docs/scripts/third-party/tocbot.min.js +1 -0
- package/docs/static/bitcoin.jpeg +0 -0
- package/docs/static/home.md +31 -0
- package/docs/static/logo-ecosystem.png +0 -0
- package/docs/static/logo.png +0 -0
- package/docs/styles/clean-jsdoc-theme-base.css +1159 -0
- package/docs/styles/clean-jsdoc-theme-dark.css +412 -0
- package/docs/styles/clean-jsdoc-theme-light.css +482 -0
- package/docs/styles/clean-jsdoc-theme-scrollbar.css +30 -0
- package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
- package/docs/styles/clean-jsdoc-theme.min.css +1 -0
- package/extend/bajo/hook/waibu@on-close.js +5 -0
- package/extend/bajo/hook/waibu@on-ready.js +5 -0
- package/{bajo/hook/on-request.js → extend/bajo/hook/waibu@on-request.js} +6 -6
- package/{bajo/hook/on-response.js → extend/bajo/hook/waibu@on-response.js} +2 -2
- package/index.js +267 -51
- package/lib/app-hook.js +2 -2
- package/lib/app.js +9 -8
- package/lib/build-locals.js +8 -8
- package/lib/collect-route-path-handlers.js +3 -2
- package/lib/handle-download.js +2 -2
- package/lib/handle-forward.js +1 -1
- package/lib/home.js +2 -2
- package/lib/{log-routes.js → print-routes.js} +3 -3
- package/lib/webapp-scope/attach-intl.js +4 -4
- package/lib/webapp-scope/handle-compress.js +1 -1
- package/lib/webapp-scope/handle-cors.js +1 -1
- package/lib/webapp-scope/handle-helmet.js +1 -1
- package/lib/webapp-scope/handle-multipart-body.js +3 -3
- package/lib/webapp-scope/handle-rate-limit.js +2 -2
- package/lib/webapp-scope/is-route-disabled.js +9 -5
- package/lib/webapp-scope/merge-route-hooks.js +2 -2
- package/lib/webapp-scope/route-hook.js +1 -1
- package/package.json +7 -2
- package/wiki/CONFIG.md +45 -0
- package/wiki/CONTRIBUTING.md +5 -0
- package/wiki/DEV-GUIDE.md +1 -0
- package/wiki/ECOSYSTEM.md +19 -0
- package/wiki/GETTING-STARTED.md +76 -0
- package/wiki/USER-GUIDE.md +1 -0
- package/bajo/hook/on-close.js +0 -5
- package/bajo/hook/on-ready.js +0 -5
- /package/{bajo/hook/on-route.js → extend/bajo/hook/waibu@on-route.js} +0 -0
- /package/{bajo → extend/bajo}/intl/en-US.json +0 -0
- /package/{bajo → extend/bajo}/intl/id.json +0 -0
- /package/{bajoTemplate → extend/bajoTemplate}/layout/email.html +0 -0
- /package/{bajoTemplate → extend/bajoTemplate}/layout/email.id.html +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function detect (detector = [], req, reply) {
|
|
2
|
-
const { get, map, trim, orderBy } = this.lib._
|
|
2
|
+
const { get, map, trim, orderBy } = this.app.lib._
|
|
3
3
|
const supported = get(this, 'app.bajo.config.intl.supported', [this.app.bajo.config.lang])
|
|
4
4
|
const defLang = get(this, 'app.bajo.config.intl.fallback', this.app.bajo.config.lang)
|
|
5
5
|
let lang = null
|
|
@@ -49,12 +49,12 @@ function detect (detector = [], req, reply) {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
async function attachIntl (detector = [], req, reply) {
|
|
52
|
-
const { get } = this.lib._
|
|
52
|
+
const { get } = this.app.lib._
|
|
53
53
|
detect.call(this, detector, req, reply)
|
|
54
|
-
const defNs = get(req, 'routeOptions.config.ns', this.
|
|
54
|
+
const defNs = get(req, 'routeOptions.config.ns', this.ns)
|
|
55
55
|
req.t = (text, ...args) => {
|
|
56
56
|
args.push({ lang: req.lang })
|
|
57
|
-
return this.app[defNs].
|
|
57
|
+
return this.app[defNs].t(text, ...args)
|
|
58
58
|
// return result.replaceAll("'", ''').replaceAll('"', '"')
|
|
59
59
|
}
|
|
60
60
|
req.format = (value, type = 'auto', opts = {}) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import compress from '@fastify/compress'
|
|
2
2
|
|
|
3
3
|
async function handleCompress (ctx, options = {}) {
|
|
4
|
-
const { defaultsDeep } = this.lib.aneka
|
|
4
|
+
const { defaultsDeep } = this.app.lib.aneka
|
|
5
5
|
if (options === false) return this.log.warn('middlewareDisabled%s', 'compress')
|
|
6
6
|
const opts = defaultsDeep(options, this.app.waibu.config.compress)
|
|
7
7
|
await ctx.register(compress, opts)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import cors from '@fastify/cors'
|
|
2
2
|
|
|
3
3
|
async function handleCors (ctx, options = {}) {
|
|
4
|
-
const { defaultsDeep } = this.lib.aneka
|
|
4
|
+
const { defaultsDeep } = this.app.lib.aneka
|
|
5
5
|
if (options === false) return this.log.warn('middlewareDisabled%s', 'cors')
|
|
6
6
|
const opts = defaultsDeep(options, this.app.waibu.config.cors)
|
|
7
7
|
await ctx.register(cors, opts)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import helmet from '@fastify/helmet'
|
|
2
2
|
|
|
3
3
|
async function handleHelmet (ctx, options = {}) {
|
|
4
|
-
const { defaultsDeep } = this.lib.aneka
|
|
4
|
+
const { defaultsDeep } = this.app.lib.aneka
|
|
5
5
|
if (options === false) return this.log.warn('middlewareDisabled%s', 'helmet')
|
|
6
6
|
const opts = defaultsDeep(options, this.app.waibu.config.helmet)
|
|
7
7
|
await ctx.register(helmet, opts)
|
|
@@ -6,7 +6,7 @@ const pump = promisify(pipeline)
|
|
|
6
6
|
|
|
7
7
|
async function onFileHandler () {
|
|
8
8
|
const { getPluginDataDir } = this.app.bajo
|
|
9
|
-
const { fs } = this.lib
|
|
9
|
+
const { fs } = this.app.lib
|
|
10
10
|
const dir = `${getPluginDataDir('waibu')}/upload`
|
|
11
11
|
return async function (part) {
|
|
12
12
|
// 'this' is the fastify context here
|
|
@@ -18,8 +18,8 @@ async function onFileHandler () {
|
|
|
18
18
|
|
|
19
19
|
async function handleMultipartBody (ctx, options = {}) {
|
|
20
20
|
const { importPkg } = this.app.bajo
|
|
21
|
-
const { defaultsDeep, isSet } = this.lib.aneka
|
|
22
|
-
const { isArray, map, trim, isPlainObject, isEmpty } = this.lib._
|
|
21
|
+
const { defaultsDeep, isSet } = this.app.lib.aneka
|
|
22
|
+
const { isArray, map, trim, isPlainObject, isEmpty } = this.app.lib._
|
|
23
23
|
const parseVar = await importPkg('bajo:dotenv-parse-variables')
|
|
24
24
|
if (options === false) return this.log.warn('middlewareDisabled%s', 'multipart')
|
|
25
25
|
const opts = defaultsDeep(options, this.app.waibu.config.multipart)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import rateLimit from '@fastify/rate-limit'
|
|
2
2
|
|
|
3
3
|
async function handleRateLimit (ctx, options = {}) {
|
|
4
|
-
const { cloneDeep } = this.lib._
|
|
5
|
-
const { defaultsDeep } = this.lib.aneka
|
|
4
|
+
const { cloneDeep } = this.app.lib._
|
|
5
|
+
const { defaultsDeep } = this.app.lib.aneka
|
|
6
6
|
if (options === false) return this.log.warn('middlewareDisabled%s', 'rateLimit')
|
|
7
7
|
const opts = defaultsDeep(options, this.app.waibu.config.rateLimit)
|
|
8
8
|
await ctx.register(rateLimit, cloneDeep(opts))
|
|
@@ -5,14 +5,18 @@ function santizeMethods (methods = '*') {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
async function isRouteDisabled (url, method, matchers = []) {
|
|
8
|
-
const { outmatch } = this.lib
|
|
9
|
-
const { isString, intersection, cloneDeep } = this.lib._
|
|
8
|
+
const { outmatch } = this.app.lib
|
|
9
|
+
const { isString, intersection, cloneDeep } = this.app.lib._
|
|
10
10
|
const items = []
|
|
11
11
|
for (let m of cloneDeep(matchers)) {
|
|
12
12
|
if (isString(m)) m = { path: m }
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
try {
|
|
14
|
+
m.path = this.app.waibu.routePath(m.path)
|
|
15
|
+
m.methods = santizeMethods(m.methods)
|
|
16
|
+
items.push(m)
|
|
17
|
+
} catch (err) {
|
|
18
|
+
throw this.error(`${m.path}: ${err.message}`)
|
|
19
|
+
}
|
|
16
20
|
}
|
|
17
21
|
const matcher = items.find(i => {
|
|
18
22
|
const isMatch = outmatch(i.path)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
async function mergeRouteHooks (def, withHandler = true) {
|
|
2
|
-
const { last, isFunction } = this.lib._
|
|
3
|
-
const { hookTypes } = this.app.waibu
|
|
2
|
+
const { last, isFunction } = this.app.lib._
|
|
3
|
+
const { hookTypes } = this.app.pluginClass.waibu
|
|
4
4
|
const hooks = [...hookTypes]
|
|
5
5
|
const me = this
|
|
6
6
|
if (withHandler) hooks.push('handler')
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
async function routeHook (ns) {
|
|
2
2
|
const ctx = this.app[ns].instance
|
|
3
3
|
const { runHook } = this.app.bajo
|
|
4
|
-
const { hookTypes } = this.app.waibu
|
|
4
|
+
const { hookTypes } = this.app.pluginClass.waibu
|
|
5
5
|
for (const hook of hookTypes) {
|
|
6
6
|
ctx.addHook(hook, async function (...args) {
|
|
7
7
|
args.push(this)
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "waibu",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Web Framework for Bajo",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
7
|
+
"build-doc": "jsdoc -c .jsdoc.conf.json",
|
|
8
|
+
"test": "mocha"
|
|
8
9
|
},
|
|
9
10
|
"type": "module",
|
|
10
11
|
"bajo": {
|
|
@@ -47,5 +48,9 @@
|
|
|
47
48
|
"fastify-no-icon": "^7.0.0",
|
|
48
49
|
"query-string": "^9.1.1",
|
|
49
50
|
"waibu-fastify-static": "^1.1.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"clean-jsdoc-theme": "^4.3.0",
|
|
54
|
+
"jsdoc-plugin-intersection": "^1.0.4"
|
|
50
55
|
}
|
|
51
56
|
}
|
package/wiki/CONFIG.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Config Object
|
|
2
|
+
|
|
3
|
+
| Key Name | Type | Default | Description |
|
|
4
|
+
| ------- | ---- | ----- | ----------- |
|
|
5
|
+
| ```server``` | ```object``` | | |
|
|
6
|
+
| ```host``` | ```string``` | ```127.0.0.1``` | |
|
|
7
|
+
| ```port``` | ```number``` | ```7777``` | |
|
|
8
|
+
| ```factory``` | ```object``` | | [Fastify Server](https://fastify.dev/docs/latest/Reference/Server) factory options |
|
|
9
|
+
| ```trustProxy``` | ```boolean``` | ```true``` | |
|
|
10
|
+
| ```bodyLimit``` | ```number``` | ```10485760``` | |
|
|
11
|
+
| ```pluginTimeout``` | ```number``` | ```30000``` | |
|
|
12
|
+
| ```deferLog``` | ```boolean``` | ```false``` | Set ```true``` to defer log at Fastify onResponse |
|
|
13
|
+
| ```prefixVirtual``` | ```string``` | ```~``` | Virtual route prefix to use |
|
|
14
|
+
| ```printRoutes``` | ```boolean``` | ```true``` | Print routes on startup |
|
|
15
|
+
| ```cors``` | ```object``` | | Defaults to [Fastify Cors](https://github.com/fastify/fastify-cors) options |
|
|
16
|
+
| ```compress``` | ```object``` | | Defaults to [Fastify Compress](https://github.com/fastify/fastify-compress) options |
|
|
17
|
+
| ```helmet``` | ```object``` | | Defaults to [Fastify Helmet](https://github.com/fastify/fastify-helmet) options |
|
|
18
|
+
| ```rateLimit``` | ```object``` | | Defaults to [Fastify Rate Limit](https://github.com/fastify/fastify-rate-limit) options |
|
|
19
|
+
| ```multipart``` | ```object``` | | Defaults to [Fastify Multipart](https://github.com/fastify/fastify-multipart) options |
|
|
20
|
+
| ```attachFieldsToBody``` | ```boolean``` | ```true``` | |
|
|
21
|
+
| ```limits``` | ```object``` | | |
|
|
22
|
+
| ```parts``` | ```number``` | ```100``` | |
|
|
23
|
+
| ```noIcon``` | ```boolean``` | ```true``` | |
|
|
24
|
+
| ```underPressure``` | ```object``` | | Defaults to [Fastify Under Pressure](https://github.com/fastify/fastify-under-pressure) options |
|
|
25
|
+
| ```forwardOpts``` | ```object``` | | Options for route forward |
|
|
26
|
+
| ```disableRequestLogging``` | ```boolean``` | ```true``` | |
|
|
27
|
+
| ```undici``` | ```object``` | | Defaults to [Undici](https://github.com/nodejs/undici) options |
|
|
28
|
+
| ```connections``` | ```number``` | ```128``` | |
|
|
29
|
+
| ```pipelining``` | ```number``` | ```1``` | |
|
|
30
|
+
| ```keepAliveTimeout``` | ```number``` | ```60000``` | |
|
|
31
|
+
| ```tls``` | ```object``` | | |
|
|
32
|
+
| ```rejectUnauthorized``` | ```boolean``` | ```false``` | |
|
|
33
|
+
| ```qsKey``` | ```object``` | | Query string keys used to build model/database filter |
|
|
34
|
+
| ```bbox``` | ```string``` | ```bbox``` | Key to use for bbox setting |
|
|
35
|
+
| ```bboxLatField``` | ```string``` | ```bboxLatField``` | Key to use to determine bbox's latitude |
|
|
36
|
+
| ```bboxLngField``` | ```string``` | ```bboxLngField``` | Key to use to determine bbox's longitude |
|
|
37
|
+
| ```query``` | ```string``` | ```query``` | Key to use for query |
|
|
38
|
+
| ```match``` | ```string``` | ```match``` | Key to enter fulltext matching |
|
|
39
|
+
| ```skip``` | ```string``` | ```skip``` | Key to skip page |
|
|
40
|
+
| ```page``` | ```string``` | ```page``` | Key to go to page number |
|
|
41
|
+
| ```limit``` | ```string``` | ```limit``` | Key to limit model per page |
|
|
42
|
+
| ```sort``` | ```string``` | ```sort``` | Key to sort model |
|
|
43
|
+
| ```fields``` | ```string``` | ```fields``` | Key to show model fields |
|
|
44
|
+
| ```lang``` | ```string``` | ```lang``` | Key for language setting |
|
|
45
|
+
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thanks very much to everyone who wants to join as a contributor, but I have committed to devoting 100% of my time to this project. Therefore, I'm currently unable to accept pull requests from anyone until the project is large enough for me to manage it independently.
|
|
4
|
+
|
|
5
|
+
However, I am available if you encounter any bugs that require immediate fixes. Please report your issues in a GitHub issue, and I'll try to address them promptly. I'm also open to criticism and suggestions for improvements or requests for new features.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Developer Guide
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Ecosystem
|
|
2
|
+
|
|
3
|
+
| Package | Docs | NS | Alias | Description |
|
|
4
|
+
| ------- | ---- | -- | ----- | ----------- |
|
|
5
|
+
| [waibu](https://github.com/ardhi/waibu) | [Docs](https://ardhi.github.io/waibu) | waibu | w |Waibu Web Framework |
|
|
6
|
+
| [waibu-admin](https://github.com/ardhi/waibu-admin) | [Docs](https://ardhi.github.io/waibu-admin) | waibuAdmin | wa | Waibu Admin |
|
|
7
|
+
| [waibu-alpinejs](https://github.com/ardhi/waibu-alpinejs) | [Docs](https://ardhi.github.io/waibu-alpinejs) | waibuAlpinejs | walp | Alpine.js Support |
|
|
8
|
+
| [waibu-blu](https://github.com/ardhi/waibu-blu) | [Docs](https://ardhi.github.io/waibu-blu) | waibuBlu | wblu | Blu theme |
|
|
9
|
+
| [waibu-bootstrap](https://github.com/ardhi/waibu-bootstrap) | [Docs](https://ardhi.github.io/waibu-bootstrap) | waibuBootstrap | wbs | Bootstrap Support |
|
|
10
|
+
| [waibu-bootstrap-icons](https://github.com/ardhi/waibu-bootstrap-icons) | [Docs](https://ardhi.github.io/waibu-bootstrap-icons) | waibuBootstrapIcons | wbsi | Bootstrap Icons Support |
|
|
11
|
+
| [waibu-bootswatch](https://github.com/ardhi/waibu-bootswatch) | [Docs](https://ardhi.github.io/waibu-bootswatch) | waibuBootswatch | wbw | Bootswatch Support |
|
|
12
|
+
| [waibu-db](https://github.com/ardhi/waibu-db) | [Docs](https://ardhi.github.io/waibu-db) | waibuDb | wdb | Database helper |
|
|
13
|
+
| [waibu-extra](https://github.com/ardhi/waibu-extra) | [Docs](https://ardhi.github.io/waibu-extra) | waibuExtra | wx | Most used 3rd party libs |
|
|
14
|
+
| [waibu-maps](https://github.com/ardhi/waibu-maps) | [Docs](https://ardhi.github.io/waibu-maps) | waibuMaps | wmaps | Maps Support |
|
|
15
|
+
| [waibu-mpa](https://github.com/ardhi/waibu-mpa) | [Docs](https://ardhi.github.io/waibu-mpa) | waibuMpa | wmpa | Multi pages app |
|
|
16
|
+
| [waibu-phosphor](https://github.com/ardhi/waibu-phosphor) | [Docs](https://ardhi.github.io/waibu-phosphor) | waibuPhosphor | wpp | Phosphoricons Support |
|
|
17
|
+
| [waibu-rest-api](https://github.com/ardhi/waibu-rest-api) | [Docs](https://ardhi.github.io/waibu-rest-api) | waibuRestApi | wra | Rest API |
|
|
18
|
+
| [waibu-static](https://github.com/ardhi/waibu-static) | [Docs](https://ardhi.github.io/waibu-static) | waibuStatic | wstatic | Static asset |
|
|
19
|
+
| [waibu-swagger](https://github.com/ardhi/waibu-swagger) | [Docs](https://ardhi.github.io/waibu-swagger) | waibuSwagger | wswagger | Rest API Documentation |
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
> If you're new to the [Waibu Web Framework](https://ardhi.github.io/waibu), we recommend you to read and follow along with [Bajo Tutorial](https://ardhi.github.io/bajo/tutorial-01-getting-started.html) and [Dobo Tutorial](https://ardhi.github.io/dobo/tutorial-01-getting-started.html) first, as this document is the continuation of them
|
|
4
|
+
|
|
5
|
+
Bajo also has a sub-framework for serving the web called [Waibu](https://ardhi.github.io/waibu).
|
|
6
|
+
|
|
7
|
+
[Fastify](https://fastify.dev) and its ecosystem have been chosen as the web engine. Fastify is known to be one of the fastest, most solid, and robust web frameworks available for Node.js. Waibu wraps Fastify and its plugins to work like the Bajo plugin system and introduces several methods to make working with Fastify easier and more enjoyable.
|
|
8
|
+
|
|
9
|
+
To install Waibu and its dependencies, do this:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
$ npm install waibu bajo-extra
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
and add ```waibu``` and ```bajo-extra``` to ```data/config/.plugins``` file.
|
|
16
|
+
|
|
17
|
+
By default, Waibu listens on host ```127.0.0.1``` and port ```7771```, so you can open your favorite browser and point it to the URL ```http://localhost:7771```.
|
|
18
|
+
|
|
19
|
+
A web framework is a very broad topic on its own. To make it more manageable, Waibu introduces the concept of a web app: a normal Bajo plugin that extends Waibu by providing a very specific task.
|
|
20
|
+
|
|
21
|
+
### Static Resources
|
|
22
|
+
|
|
23
|
+
The first web app to note is the one that serves static resources, [waibu-static](https://github.com/ardhi/waibu-static). Installation is very straightforward:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
$ npm install waibu-static
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
and again, don't forget to add ```waibu-static``` to ```data/config/.plugins``` file.
|
|
30
|
+
|
|
31
|
+
#### Static Assets
|
|
32
|
+
|
|
33
|
+
This plugin serves static assets:
|
|
34
|
+
- With the route path ```/asset/{ns-prefix}/*```.
|
|
35
|
+
- Static assets are served from the ```{plugin-dir}/extend/waibuStatic/asset``` directory.
|
|
36
|
+
- Where ```{ns-prefix}``` is a prefix string defined by its corresponding plugin. If this prefix is missing, it defaults to the plugin's alias.
|
|
37
|
+
- And ```{plugin-dir}``` is the plugin's base directory.
|
|
38
|
+
|
|
39
|
+
Now, create the ```main/extend/waibuStatic/asset``` directory and add some static assets to it. For example, let's create ```main/extend/waibuStatic/asset/hello.txt``` and add some text in it.
|
|
40
|
+
|
|
41
|
+
When you restart your app, your screen should show you a bunch of logs like these:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
$ node index.js --log-level=trace
|
|
45
|
+
...
|
|
46
|
+
2025-09-19T01:09:42.338Z +11ms INFO: waibu Server is ready
|
|
47
|
+
2025-09-19T01:09:42.346Z +8ms TRACE: waibu Loaded routes
|
|
48
|
+
2025-09-19T01:09:42.346Z +0ms TRACE: waibu - /asset* (OPTIONS)
|
|
49
|
+
2025-09-19T01:09:42.347Z +1ms TRACE: waibu - /asset/main/* (HEAD|GET)
|
|
50
|
+
2025-09-19T01:09:42.347Z +0ms TRACE: waibu - /asset/static/* (HEAD|GET)
|
|
51
|
+
2025-09-19T01:09:42.348Z +1ms TRACE: waibu - /asset/~/bajo/dayjs/* (HEAD|GET)
|
|
52
|
+
...
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
If you visit ```http://localhost:7771/asset/main/hello.txt```, you'll get the same exact content you just added.
|
|
57
|
+
|
|
58
|
+
#### Virtual Assets
|
|
59
|
+
|
|
60
|
+
In the app logs above, you might be wondering what route paths starting with ```/asset/~/{ns}``` are all about. In ```waibu-static``` terms, it's called virtual assets. It's a way to export any directory within a plugin to be served as static assets.
|
|
61
|
+
|
|
62
|
+
Imagine you're writing a plugin that needs a specific package called ```hybrid-pkg``` from npm, and your frontend needs the exact same package. Without virtual assets, you would have to copy the exported files or directory to your plugin's asset directory. With virtual assets, you only need to do the following:
|
|
63
|
+
|
|
64
|
+
1. Create ```{your-plugin-ns}/extend/waibuStatic/virtual.json```
|
|
65
|
+
2. Enter the following items into the file:
|
|
66
|
+
```json
|
|
67
|
+
[{
|
|
68
|
+
"prefix": "hybrid-pkg",
|
|
69
|
+
"root": "node_modules/hybrid-pkg/dist"
|
|
70
|
+
}]
|
|
71
|
+
```
|
|
72
|
+
The above statement instructs virtual assets to create the route path ```/asset/~/{your-plugin-prefix}/hybrid-pkg/*``` that is mapped to ```{your-plugin-dir}/node_modules/hybrid-pkg/dist```
|
|
73
|
+
3. Restart your app
|
|
74
|
+
|
|
75
|
+
Now you can use the same resource for frontend. Your request will be in the form of ```http://localhost:7771/asset/~/{your-plugin-prefix}/hybrid-pkg/file.js```
|
|
76
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# User Guide
|
package/bajo/hook/on-close.js
DELETED
package/bajo/hook/on-ready.js
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|