Waibu

Waibu Web Framework plugin for Bajo. This is the main foundation of all web apps attached to the system through a route prefix. Those web apps are then build as childrens with its own fastify's context.

There are currently 3 web apps available:

You should write your code as the extension of above web apps. Not to this main app, unless you want to use write custom web apps with its own context.

Constructor

new Waibu()

Members

config :Object

Type:
  • Object

findRoute

Find route by route name

routeDir

Get route directory by plugin's name

(static, constant) alias :string

Type:
  • string
Default Value
  • 'w'

(static, constant) dependencies :Array.<string>

Type:
  • Array.<string>
Default Value
  • ['bajo-extra']

(static, constant) escapeChars :TEscapeChars

Type:
  • TEscapeChars

(static, constant) hookTypes :Array.<string>

Type:
  • Array.<string>
Default Value
  • ['onRequest', 'onResponse', 'preParsing', 'preValidation', 'preHandler', 'preSerialization', 'onSend', 'onTimeout', 'onError']

Methods

escape(text) → {string}

Escape text

Parameters:
NameTypeDescription
textstring
Returns:
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.

Parameters:
NameTypeAttributesDefaultDescription
urlstring

Also support ns based url

optsObject<optional>
{}

node's fetch options

extraObject<optional>
{}

See bajo-extra

Returns:
Type: 
Object

getIp(req) → {string}

Get visitor IP from fastify's request object

Parameters:
NameTypeDescription
reqObject

request object

Returns:
Type: 
string

getOrigin(req) → {string}

Get origin of fastify's request object

Parameters:
NameTypeDescription
reqObject
Returns:
Type: 
string

getPluginByPrefix(prefix) → {Object}

Get plugin by prefix

Parameters:
NameTypeDescription
prefixstring
Returns:
Type: 
Object

getPluginPrefix(name, webAppopt) → {string}

Get plugin's prefix by name

Parameters:
NameTypeAttributesDefaultDescription
namestring

Plugin's name

webAppstring<optional>
waibuMpa

Web app to use

Returns:
Type: 
string

getRoutes(groupedopt, liteopt) → {Array}

Get all available routes

Parameters:
NameTypeAttributesDefaultDescription
groupedboolean<optional>
false

Returns as groups of urls and methods

lite*<optional>
false

Retuns only urls and methods

Returns:
Type: 
Array

getUploadedFiles(reqId, fileUrlopt, returnDir) → {Object|Array}

Get uploaded files by request ID

Parameters:
NameTypeAttributesDefaultDescription
reqIdstring

Request ID

fileUrlboolean<optional>
false

If true, files returned as file url format (file:///...)

returnDir*

If true, also return its directory

Returns:
  • Returns object if returnDir is true, array of files otherwise
Type: 
Object | Array

(async) init()

Initialize plugin

isIntlPath(ns) → {boolean}

Is namespace's path contains language detector token?

Parameters:
NameTypeDescription
nsstring

Plugin name

Returns:
Type: 
boolean

parseFilter(req) → {Object}

Parse filter found from Fastify's request based on keys set in config object

Parameters:
NameTypeDescription
reqObject

Request object

Returns:
Type: 
Object

routePath(name, optionsopt) → {string}

Get route path by route's name:

  • If it is a mailto: or tel: url, it returns as is
  • If it is a ns based name, it will be parsed first
Parameters:
NameTypeAttributesDefaultDescription
namestring
optionsObject<optional>
{}

Options object

Properties
NameTypeAttributesDefaultDescription
basestring<optional>
waibu

Base namespace

guessHostboolean<optional>

If true, guest host if host is not set

queryObject<optional>
{}

Query string's object. If provided, it will be added to returned value

paramsObject<optional>
{}

Parameter object. If provided, it will be merged to returned value

Returns:
Type: 
string

(async) sendMail(tpl, paramsopt)

Method to send mail through Masohi Messaging System. It is a thin wrapper for masohi-mail send method.

If masohi is not loaded, nothing is delivered.

Parameters:
NameTypeAttributesDefaultDescription
tplstring | Array

Mail's template to use. If a string is given, the same template will be used for html & plaintext versions. Otherwise, the first template will be used for html mail, and the second one is for it's plaintext version

paramsObject<optional>
{}

masohi-mail's params object.

Returns:

(async) start()

Start plugin

unescape(text) → {string}

Unescape text using TEscapeChars rules

Parameters:
NameTypeDescription
textstring

Text to unescape

Returns:
Type: 
string

unescapeBlock(content, start, end, startReplacer, endReplacer) → {string}

Recursively unescape block of texts

Parameters:
NameTypeDescription
contentstring

Source content

startstring

Block's start

endstring

Block's end

startReplacerstring

Token to use as block's start replacer

endReplacerstring

Token to use as block's end replacer

Returns:
Type: 
string

Type Definitions

TEscapeChars

Type:
  • Object
Properties
NameTypeDefaultDescription
<string&lt;
>string&gt;
"string&quot;
'string&apos;