Skip to main content

Class: Engine

ghostly-engine.Engine

The Ghostly Engine API.

Constructors

constructor

new Engine(config?)

Constructs a Ghostly Engine instance.

Parameters

NameTypeDescription
configPartial<EngineConfig>Optional Ghostly Engine configuration.

Defined in

ghostly-engine/src/engine.ts:187

Methods

httpRequestHandler

httpRequestHandler(request, response?, pathName?): Promise<WSResponse>

Handle an incoming HTTP request and serialize the result accordingly.

This method can either be used directly as a Node.js HTTP RequestListener, or as a utility method. If response is specified, the result will be serialized as Buffer/WSRenderResponse/WSErrorResponse, depending on the request and its outcome. In either case, the raw WSResponse will be returned as well.

The Web Service/HTTP interface supports three different processing modes:

  1. GET requests. The following query parameters should be specified:

    • template: URL of template to render.
    • view: Media type of view to render.
    • params: Optional view params as (URL-encoded) JSON.
    • document: The model to render, as a string.
    • contentType: The model's media type.

    The response will be the rendered view.

  2. POST requests that includes a template query parameter:

    • template: URL of template to render.
    • view: Media type of view to render.
    • params: Optional view params as (URL-encoded) JSON.

    The request body should be the model. The response will be the rendered view.

  3. POST request with no query parameters.

    The request body should be a JSON-encoded WSRenderRequest message, and the response(s) will be returned as WSRenderResponse, i.e. a WSRenderResult array, which can also include attachments and events emitted from the template.

see WSRenderRequest

see WSRenderResponse

see WSRenderResult

see WSErrorResponse

Parameters

NameTypeDescription
requestIncomingMessageThe Node.js HTTP request to handle.
response?ServerResponseIf specified, the response will be serialized and written to this ServerResponse object.
pathName?stringThe URL path to match. Defaults to '/'.

Returns

Promise<WSResponse>

A WSResponse representation of the result.

Defined in

ghostly-engine/src/engine.ts:303


start

start(): Promise<Engine>

Launch the configured number of browser instances and get ready for work.

Returns

Promise<Engine>

Defined in

ghostly-engine/src/engine.ts:215


stop

stop(): Promise<Engine>

Close all running browser instances and clean up internal resources.

Returns

Promise<Engine>

Defined in

ghostly-engine/src/engine.ts:228


template

template(uri, templateConfig?): TemplateEngine

Create a TemplateEngine instance using the specified Ghostly template URL.

Parameters

NameTypeDescription
uristringThe URL of the Ghostly template to use.
templateConfigPartial<TemplateConfig>-

Returns

TemplateEngine

Defined in

ghostly-engine/src/engine.ts:250