Home Reference Source Test Repository
import Engine from 'trek/src/Engine.js'
public class | source

Engine

Extends:

Koa → Engine

Direct Subclass:

Trek

The Trek Engine Core

Constructor Summary

Public Constructor
public

constructor(rootPath: String)

Member Summary

Public Members
public

body: *

public

cache: *

public

config: *

public

context: *

public

engines: *

public

env: *

public
public
public get

logger: winston.Logger: *

The app `logger`
public
public get

path: String: *

Get the app prefix path
public get

paths: Paths: *

The `config.paths` delegation
public get
The app working `rootPath` directory
public set

rootPath(root: String): *

Set a working `rootPath` directory for app
public get

routeMapper: RouteMapper: *

Get route mapper.
public

router: *

public

server: *

public get
Get all servides
public

state: *

Method Summary

Public Methods
public

all(path: String, handler: GeneratorFunction[]): Engine

Special-cased "all" method, applying the given route `path`, middleware, and handler to _every_ HTTP method.
public

* bootstrap(): void

Boot the app
public
Register the given template engine callback `fn` * as `ext`.
public
Serves the default favicon - GET /favicon.ico
public

getService(key: String): *

Get a service by key
public

index(file: String, options: Object): Engine

Index serves index file
public

* loadServices(): void

Load services
public

match(methods: String[], path: String, handler: GeneratorFunction[]): Engine

Match adds a route > handler to the router for multiple HTTP methods provided
public

* render(view: String, options: Object): String

Render `view` with the given `options`
public

run(args: *): Promise

Run the app
public

serveDir(path: String, dir: String, options: Object): Engine

Serves files from a directory
public

serveFile(path: String, file: String, options: Object): Engine

Serves a file
public

set(key: *, value: *): Engine

Stores the `value` with `key` into `app.config`
public

setService(key: String, service: *): void

Stores a service
public

static(path: String, dir: String, options: Object): Engine

Serves static files from a directory.

Public Constructors

public constructor(rootPath: String) source

Params:

NameTypeAttributeDescription
rootPath String

The app root path.

Public Members

public body: * source

public cache: * source

public config: * source

public context: * source

public engines: * source

public env: * source

public initialized: boolean source

public isBooted: boolean source

public get logger: winston.Logger: * source

The app logger

Return:

winston.Logger

public mountpath: string source

public get path: String: * source

Get the app prefix path

Return:

String

public get paths: Paths: * source

The config.paths delegation

Return:

Paths

config.paths

public get rootPath: String: * source

The app working rootPath directory

Return:

String

public set rootPath(root: String): * source

Set a working rootPath directory for app

public get routeMapper: RouteMapper: * source

Get route mapper.

Return:

RouteMapper

routeMapper

public router: * source

public server: * source

public get services: Map: * source

Get all servides

Return:

Map

services

Example:


 app.services
 // return a `Map` object
 // => map

public state: * source

Public Methods

public all(path: String, handler: GeneratorFunction[]): Engine source

Special-cased "all" method, applying the given route path, middleware, and handler to every HTTP method.

Params:

NameTypeAttributeDescription
path String
handler GeneratorFunction[]

Return:

Engine

this

public * bootstrap(): void source

Boot the app

Return:

void

public engine(ext: String, fn: GeneratorFunction): Engine source

Register the given template engine callback fn * as ext.

Params:

NameTypeAttributeDescription
ext String
fn GeneratorFunction

Return:

Engine

this

public favicon(file: String): Engine source

Serves the default favicon - GET /favicon.ico

Params:

NameTypeAttributeDescription
file String

Return:

Engine

this

Example:


 app.favicon('public/favicon.ico')

public getService(key: String): * source

Get a service by key

Params:

NameTypeAttributeDescription
key String

Return:

*

service

Example:


 app.getService('db')
 // => db

public index(file: String, options: Object): Engine source

Index serves index file

Params:

NameTypeAttributeDescription
file String
options Object

Return:

Engine

this

public * loadServices(): void source

Load services

Return:

void

public match(methods: String[], path: String, handler: GeneratorFunction[]): Engine source

Match adds a route > handler to the router for multiple HTTP methods provided

Params:

NameTypeAttributeDescription
methods String[]
path String
handler GeneratorFunction[]

Return:

Engine

this

public * render(view: String, options: Object): String source

Render view with the given options

Params:

NameTypeAttributeDescription
view String

The name of view

options Object
options.cache Boolean

Boolean hinting to the engine it should cache

options.filename String

Filename of the view being rendered

Return:

String

Example:

 yield app.render('site', { name: 'trek' })

public run(args: *): Promise source

Run the app

Params:

NameTypeAttributeDescription
args *

Return:

Promise

public serveDir(path: String, dir: String, options: Object): Engine source

Serves files from a directory

Params:

NameTypeAttributeDescription
path String
dir String
options Object

Return:

Engine

this

public serveFile(path: String, file: String, options: Object): Engine source

Serves a file

Params:

NameTypeAttributeDescription
path String
file String
options Object

Return:

Engine

this

public set(key: *, value: *): Engine source

Stores the value with key into app.config

Params:

NameTypeAttributeDescription
key *
value *

Return:

Engine

this

public setService(key: String, service: *): void source

Stores a service

Params:

NameTypeAttributeDescription
key String

the service name

service *

the service instance

Return:

void

Example:


 app.setService('db', {})

public static(path: String, dir: String, options: Object): Engine source

Serves static files from a directory. It's an alias for app#serveDir

Params:

NameTypeAttributeDescription
path String
dir String
options Object

Return:

Engine

this