Members
config :Waibu.TConfig
Configuration object. To override the default configuration, you can create data/config/waibu.json
escapeChars :Waibu.TEscapeChars
hookTypes :Array.<string>
- Array.<string>
- Default Value
- ['onRequest', 'onResponse', 'preParsing', 'preValidation', 'preHandler', 'preSerialization', 'onSend', 'onTimeout', 'onError']
qs :Object
Query string parser and stringifier. It is a wrapper of query-string package.
- Object
| Name | Type | Description |
|---|---|---|
qs.parse | function | Query string parser |
qs.parseUrl | function | Query string url parser |
qs.stringify | function | Query string stringifier |
qs.stringifyUrl | function | Query string url stringifier |
Methods
(async) _handleAppHook() → {Promise.<void>}
Handle app hooks. It will run hooks for each web app and main app.
- Type:
- Promise.<void>
(async) _handleError() → {Promise.<void>}
Route error handler.
- Type:
- Promise.<void>
(async) _handleFavicon() → {Promise.<void>}
Create route for '/favicon.:ext'
Location of favicon file can be found in:
- main plugin's file; if not found, then
- site attachment; if not found, then
- static dir of theme; if not found, then
- default plugin's file
- Type:
- Promise.<void>
(async) _handleForward() → {Promise.<void>}
Handle forward. It will decorate reply object with forwardTo method.
- Type:
- Promise.<void>
(async) _handleHome() → {Promise.<void>}
Create route for '/' to redirect to home path.
- Type:
- Promise.<void>
(async) _handleNotFound() → {Promise.<void>}
Route not found handler.
- Type:
- Promise.<void>
(async) _handleRedirect(options) → {Promise.<void>}
Handle redirect. It will decorate reply object with redirectTo method.
| Name | Type | Description |
|---|---|---|
options | object |
- Type:
- Promise.<void>
(async) _handleRobotsTxt() → {Promise.<void>}
Create route for '/robots.txt'.
Location of robots.txt file can be found in:
- main plugin's file; if not found, then
- site attachment; if not found, then
- default plugin's file
- Type:
- Promise.<void>
_printRoutes() → {void}
Print all registered routes.
- Type:
- void
(async) _runWebApps() → {Promise.<void>}
Run web applications.
- Type:
- Promise.<void>
base64JsonDecode(data) → {Object}
Decode base64 encoded json string
| Name | Type | Description |
|---|---|---|
data | string | Base64 encoded JSON string |
Decoded JSON object
- Type:
- Object
base64JsonEncode(data) → {string}
Encode JSON object to base64 string
| Name | Type | Description |
|---|---|---|
data | Object | JSON object to encode |
Base64 encoded JSON string
- Type:
- string
escape(text) → {string}
Escape text
| Name | Type | Description |
|---|---|---|
text | string |
- Type:
- string
(async) exit()
Exit handler
(async) fetch(url, optsopt, extraopt) → {Object}
Fetch something from url. A wrapper of bajo-extra's fetchUrl which support bajo's ns based url.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
url | string | Also support ns based url | ||
opts | Object | <optional> | {} | node's fetch options |
extra | Object | <optional> | {} | See bajo-extra |
- Type:
- Object
findRoute(name) → {Object}
Find route by route name
| Name | Type | Description |
|---|---|---|
name | string | ns based route name |
Route object
- Type:
- Object
getHostname(req) → {string}
Get hostname from fastify's request object
| Name | Type | Description |
|---|---|---|
req | Object |
- Type:
- string
getIp(req) → {string}
Get visitor IP from fastify's request object
| Name | Type | Description |
|---|---|---|
req | Object | request object |
- Type:
- string
getOrigin(req) → {string}
Get origin from fastify's request object
| Name | Type | Description |
|---|---|---|
req | Object |
- Type:
- string
getPluginByPrefix(prefix, nsOnly) → {Object}
Get plugin by prefix
| Name | Type | Description |
|---|---|---|
prefix | string | |
nsOnly | boolean | Set |
- Type:
- Object
getPluginPrefix(name, webAppopt) → {string}
Get plugin's prefix by name
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
name | string | Plugin's name | ||
webApp | string | <optional> | waibuMpa | Web app to use |
- Type:
- string
getRoutes(groupedopt, liteopt) → {Array}
Get all available routes
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
grouped | boolean | <optional> | false | Returns as groups of urls and methods |
lite | * | <optional> | false | Retuns only urls and methods |
- Type:
- Array
getUploadedFiles(reqId, fileUrlopt, returnDir) → {Object|Array}
Get uploaded files by request ID
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
reqId | string | Request ID | ||
fileUrl | boolean | <optional> | false | If |
returnDir | * | If |
- Returns object if
returnDiristrue, array of files otherwise
- Type:
- Object |
Array
(async) init()
Initialize plugin
isIntlPath(ns) → {boolean}
Is namespace's path contains language detector token?
| Name | Type | Description |
|---|---|---|
ns | string | Plugin name |
- Type:
- boolean
parseFilter(req) → {Object}
Parse filter found from Fastify's request based on keys set in config object
| Name | Type | Description |
|---|---|---|
req | Object | Request object |
- Type:
- Object
routeDir(ns, baseNsopt) → {string}
Get route directory by plugin's name
| Name | Type | Attributes | Description |
|---|---|---|---|
ns | * | Namespace | |
baseNs | * | <optional> | Base namespace. If not provided, defaults to scope's ns |
- Type:
- string
routePath(name, optionsopt) → {string}
Get route path by route's name:
- If it is a
mailto:ortel:url, it returns as is - If it starts with
:/, name will be prefixed with itsnsautomatically - If it is a ns based name, it will be parsed first
| Name | Type | Attributes | Default | Description | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
name | string | ||||||||||||||||||||||||||||
options | Object | <optional> | {} | Options object Properties
|
- Type:
- string
(async) start()
Start plugin
unescape(text) → {string}
Unescape text using TEscapeChars rules
| Name | Type | Description |
|---|---|---|
text | string | Text to unescape |
- Type:
- string
unescapeBlock(content, start, end, startReplacer, endReplacer) → {string}
Recursively unescape block of texts
| Name | Type | Description |
|---|---|---|
content | string | Source content |
start | string | Block's start |
end | string | Block's end |
startReplacer | string | Token to use as block's start replacer |
endReplacer | string | Token to use as block's end replacer |
- Type:
- string
Type Definitions
TConfig
- Object
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
home | Object | Home configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
server | Object | Server configuration Properties
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
factory | Object | Factory configuration. @see https://fastify.dev/docs/latest/Reference/Server/#factory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
intl | Object | Internationalization configuration Properties
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
log | Object | Logging configuration Properties
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
prefixVirtual | string | Prefix for virtual routes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
favicon | boolean | | <optional> | true | Favicon configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
robotsTxt | boolean | <optional> | true | Set to 'false' to disable robots.txt route | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
qsKey | Object | Query string key configuration Properties
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
paramsCharMap | Object | <optional> | {} | Parameters character map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
route | Object | <optional> | {} | Route configuration Properties
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pageTitleFormat | string | <optional> | '%s : %s' | Page title format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
siteInfo | Object | <optional> | {} | Site information Properties
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cors | Object | <optional> | {} | CORS configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
compress | Object | <optional> | {} | Compression configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
helmet | Object | <optional> | {} | Helmet configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
rateLimit | Object | <optional> | {} | Rate limit configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
multipart | Object | <optional> | {} | Multipart configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
exposeError | boolean | <optional> | false | Expose error configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
underPressure | boolean | <optional> | false | Under pressure configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
forwardOpts | Object | <optional> | {} | Forward options configuration Properties
|
- Source
TEscapeChars
- Object
| Name | Type | Default | Description |
|---|---|---|---|
< | string | < | |
> | string | > | |
" | string | " | |
' | string | ' |