Global

Members


defaultBackendPath

when running with [NODE_RT=babel], directly use source files

Source:
utils/Helpers.js

httpMethod

Http method decorator for module controller

Source:
utils/Helpers.js

middleware

Middleware decorator for controller

Source:
utils/Helpers.js

<readonly> module:Literal :string

Common constant definitions.

Type:
  • string
Source:
enum/Literal.js

Methods


addRoute(router, method, route, actions)

Add a route to a router, skipped while the server running in deaf mode.

Parameters:
Name Type Description
router
method
route
actions
Source:
Routable.js

addRouter(nestedRouter)

Attach a router to this app module, skipped while the server running in deaf mode

Parameters:
Name Type Description
nestedRouter Router
Source:
Routable.js

enabled(feature)

Check whether a feature is enabled in the app or its hosting server.

Parameters:
Name Type Description
feature string
Source:
ModuleBase.js
Returns:
Type
bool

getMiddlewareFactory(name)

Get the factory method of a middleware from module hierarchy.

Parameters:
Name Type Description
name
Source:
Routable.js
Returns:
Type
function

getService(name)

Get a service from module hierarchy

Parameters:
Name Type Description
name
Source:
ModuleBase.js
Returns:
Type
object

loadMiddlewaresFrom(dir)

Load and regsiter middleware files from a specified path.

Parameters:
Name Type Description
dir
Source:
Routable.js

log(level, message, rest)

Default log method, may be override by loggers feature

Parameters:
Name Type Argument Description
level string

Log level

message string

Log message

rest object <repeatable>

Extra meta data

Source:
ModuleBase.js
Returns:
Type
Routable

module:Middleware_AccessLog(name, app)

Get a cached middleware from the app's object store.

Parameters:
Name Type Description
name string

Name of the middleware stored in the app's object store.

app Routable
Source:
middlewares/fromStore.js
Returns:
Type
AsyncFunction

module:Middleware_Action(controllerAction, app)

Action middleware creator

Parameters:
Name Type Description
controllerAction string
app Routable
Source:
middlewares/action.js

module:Middleware_FlashMessage()

add message to flash messages

ctx.flashMessage.warning = 'Log Out Successfully!';

read all flash messages

ctx.state.flashMessage.messages
// or ctx.flashMessage.messages

read warning message

ctx.state.flashMessage.warning

Source:
middlewares/flashMessage.js

module:Middleware_PassportCheck(options, app)

Initialize ensureLoggedIn middleware

Parameters:
Name Type Description
options object
app Routable
Properties:
Name Type Argument Description
options.loginUrl string <optional>

If given, will redirect to loginUrl if not loggedIn

options.successReturnToOrRedirect boolean <optional>

If given, will redirect to loginUrl if not loggedIn

Source:
middlewares/passportCheck.js

module:Middleware_Session(options, app)

Initialize session middleware

Parameters:
Name Type Description
options object

Session options

app Routable
Properties:
Name Type Argument Default Description
options.key string <optional>
'mowa:sid'

Cookie name defaulting to mowa.sid

options.prefix string <optional>
'mowa:sess:'

Session prefix for store, defaulting to mowa:sess:

options.maxAge number <optional>

SessionStore's expiration time (ms), defaulting to 86400000 (1 day)

options.autoCommit bool <optional>
true

Automatically commit headers (default true)

options.overwrite bool <optional>
true

Can overwrite or not (default true)

options.httpOnly bool <optional>
true

HttpOnly or not (default true)

options.signed bool <optional>
true

Signed or not

options.rolling bool <optional>
false

Force a session identifier cookie to be set on every response. The expiration is reset to the original maxAge, resetting the expiration countdown. (default is false)

options.renew bool <optional>
false

Renew session when session is nearly expired, so we can always keep user logged in. (default is false)

options.genSid function <optional>

The way of generating external session id is controlled by the options.genid, which defaults to Date.now() + '-' + uid.sync(24)

options.valid function <optional>

valid(ctx, session), valid session value before use it

options.beforeSave function <optional>

beforeSave(ctx, session), hook before save session

options.store object <optional>

Session store instance. It can be any Object that has the methods set, get, destroy like MemoryStore.

Source:
middlewares/session.js

module:Middleware_Views( [options], app)

Initiate the views middleware

Parameters:
Name Type Argument Description
options Object <optional>

Template options

app Routable

The owner app module

Properties:
Name Type Argument Description
options.extension string <optional>

Default extension for your views

options.map Object <optional>

Extensions to engines map

options.options Object <optional>

View state locals

Properties
Name Type Argument Description
cache bool <optional>

Flag to enable cache

Source:
middlewares/views.js

module:Router_Gaml(app, baseRoute, options)

Create a gaml router.

Parameters:
Name Type Description
app *
baseRoute string
options objects
Properties:
Name Type Argument Description
options.resourcesPath string <optional>
options.middlewares object | array <optional>
Source:
routers/gaml.js
Example
'<base path>': {
     gaml: {
         resourcesPath:
         middlewares:
     }
 }

 route                          http method    function of ctrl
 /:resource                     get            find
 /:resource                     post           post
 /:resource/:id                 get            findById
 /:resource/:id                 put            updateById
 /:resource/:id                 del            deleteById

module:Router_GraphQL(app, baseRoute, options)

Create a GraphQL router.

Parameters:
Name Type Description
app *
baseRoute string
options objects
Properties:
Name Type Argument Description
options.schema string
options.middlewares object | array <optional>
options.graphiql boolean <optional>
Source:
routers/graphql.js
Example
'<base path>': {
     graphql: {          
         middlewares: {},
         schema: 'graphql/schema',
         rootValue: '',
         graphiql: true
     }
 }

module:Router_Module(app, baseRoute, moduleItem)

Create a module-based router.

Parameters:
Name Type Description
app Routable
baseRoute string
moduleItem *
Source:
routers/module.js
Example
'<base path>': {
      module: {
          middlewares:
          controller:
      }
  }

  '<base path>': {
      module: "controller"
  }

module:Router_Rest(app, baseRoute, options)

Create a RESTful router.

Parameters:
Name Type Description
app *
baseRoute string
options objects
Properties:
Name Type Argument Description
options.resourcesPath string <optional>
options.middlewares object | array <optional>
Source:
routers/rest.js
Example
'<base path>': {
     rest: {
         resourcesPath:
         middlewares:
     }
 }

 route                          http method    function of ctrl
 /:resource                     get            query
 /:resource                     post           create
 /:resource/:id                 get            detail
 /:resource/:id                 put            update
 /:resource/:id                 delete         remove

mountRouter(route, router)

Attach a router to this app module by mounting the router to a route

Parameters:
Name Type Description
route *
router *
Source:
Routable.js

registerMiddlewareFactory(name, factoryMethod)

Register the factory method of a named middleware.

Parameters:
Name Type Description
name string

The name of the middleware

factoryMethod function

The factory method of a middleware

Source:
Routable.js

require(relativePath)

Require a js module from backend path

Parameters:
Name Type Description
relativePath *
Source:
ModuleBase.js

requireFromLib(relativePath)

Require a module from the source path of a library module

Parameters:
Name Type Description
relativePath *
Source:
ModuleBase.js

toWebPath(relativePath [, pathOrQuery])

Translate a relative path and query parameters if any to a url path

Parameters:
Name Type Argument Description
relativePath string

Relative path

pathOrQuery * <optional>
<repeatable>

Queries

Source:
Routable.js
Returns:
Type
string

useMiddlewares(router, middlewares)

Use middlewares

Parameters:
Name Type Description
router Router
middlewares *

Can be an array of middleware entries or a key-value list of registerred middlewares

Source:
Routable.js
Returns:
Type
Routable

Type Definitions


<async> KoaActionFunction(ctx [, next])

Koa middleware function

Parameters:
Name Type Argument Description
ctx object

The koa request and response context. See koajs about ctx details

next KoaActionFunction <optional>

Next middleware or action.

Properties:
Name Type Description
ctx.reqeust object

The koa request object.

ctx.response object

The koa response object.

Source:
serverFeatures/koa.js