Function
Static Public Summary | ||
public |
app(): Application Gets the instance of the currently running application. |
|
public |
createObject(type: string | object, params: ...*): * Creates a new object using the dependency injection (DI) container of the application. |
|
public |
async errorAction(ctx: Context, next: function) Manages the application errors. |
|
public |
Creates a middleware function managing the application errors. |
|
public |
Translates a path alias into an actual path. |
|
public |
registerType(alias: string): * Registers a type in the dependency injection (DI) container of the application. |
|
public |
Creates a middleware function setting some security-related headers. |
|
public |
Registers a path alias. |
|
public |
statusAction(ctx: Context) Sends the application status. |
|
public |
Creates a middleware function sending the application status. |
Static Public
public app(): Application source
import {app} from '@cedx/koa-core/src/application.js'
Gets the instance of the currently running application.
Test:
public createObject(type: string | object, params: ...*): * source
import {createObject} from '@cedx/koa-core/src/di.js'
Creates a new object using the dependency injection (DI) container of the application.
You may view this function as an enhanced version of the new
operator. The function supports creating an object based on one of the following forms:
- a string: a class alias representing the location and the class name of the object to be created.
- a configuration object: the object must contain a
class
element which is treated as the class alias, and the rest of the name-value pairs will be used to initialize the corresponding object properties.
Return:
* | The newly created object. |
Throw:
The object type is not supported. |
Test:
public async errorAction(ctx: Context, next: function) source
import {errorAction} from '@cedx/koa-core/src/error_action.js'
Manages the application errors.
Params:
Name | Type | Attribute | Description |
ctx | Context | The context encapsulating the client request and the server response. |
|
next | function | TODO |
public errorHandler(): function source
import {errorHandler} from '@cedx/koa-core/src/middleware.js'
Creates a middleware function managing the application errors.
public getAlias(alias: string, throwError: boolean): string source
import {getAlias} from '@cedx/koa-core/src/alias.js'
Translates a path alias into an actual path.
The translation is done according to the following procedure:
- If the given alias does not start with
@
, it is returned back without change. - Otherwise, look for the registered alias that matches the beginning part of the given alias. If it exists, replace the matching part of the given alias with the corresponding registered path.
- Throw an error or return an empty string, depending on the
throwError
parameter.
Return:
string | The path corresponding to the alias, or an empty string if the root alias is not previously registered. |
Throw:
The path alias is invalid while |
Test:
public registerType(alias: string): * source
import {registerType} from '@cedx/koa-core/src/di.js'
Registers a type in the dependency injection (DI) container of the application.
A type is registered using a class alias specifying the location and the name of the type to be registered. For example:
@app/components/FooBar
: will be resolved to theFooBar
class exported by the@app/components.js
module, or the@app/components/index.js
module.@core/FooBar
: will be resolved to theFooBar
class exported by this package.@npm/foo/FooBar
: will be resolved to theFooBar
class exported by thefoo
package located in thenode_modules
folder.@npm/@foo/bar/FooBar
: will be resolved to theFooBar
class exported by the@foo/bar
package located in thenode_modules
folder.
Params:
Name | Type | Attribute | Description |
alias | string | The class alias representing the location and the name of the type to be registered. |
Return:
* | The resolved type. |
Throw:
The specified class alias is invalid, or the corresponding type is not found. |
Test:
public securityHandler(): function source
import {securityHandler} from '@cedx/koa-core/src/middleware.js'
Creates a middleware function setting some security-related headers.
public setAlias(name: string, path: string) source
import {setAlias} from '@cedx/koa-core/src/alias.js'
Registers a path alias.
It must start with the character @
so that it can be easily differentiated from non-alias paths.
Alias defined without leading @
will be prefixed with @
character.
Any trailing /
and \
characters in the given path will be trimmed.
Throw:
The specified name is empty. |
Test:
public statusAction(ctx: Context) source
import {statusAction} from '@cedx/koa-core/src/status_action.js'
Sends the application status.
Params:
Name | Type | Attribute | Description |
ctx | Context | The context encapsulating the client request and the server response. |
public statusHandler(): function source
import {statusHandler} from '@cedx/koa-core/src/middleware.js'
Creates a middleware function sending the application status.