Class: Engine
ghostly-engine.Engine
The Ghostly Engine API.
Constructors
constructor
• new Engine(config?)
Constructs a Ghostly Engine instance.
Parameters
| Name | Type | Description |
|---|---|---|
config | Partial<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:
GETrequests. 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.
POSTrequests that includes atemplatequery 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.
POSTrequest 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
| Name | Type | Description |
|---|---|---|
request | IncomingMessage | The Node.js HTTP request to handle. |
response? | ServerResponse | If specified, the response will be serialized and written to this ServerResponse object. |
pathName? | string | The 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
| Name | Type | Description |
|---|---|---|
uri | string | The URL of the Ghostly template to use. |
templateConfig | Partial<TemplateConfig> | - |