-
Notifications
You must be signed in to change notification settings - Fork 0
Application
Anton edited this page Dec 21, 2019
·
39 revisions
The application is the instance created by the Goa class. It can provide the callback listener via the callback
method, as well as start listening for connections itself. Application extends the EventEmitter class, so it's possible to listen on events, e.g.,
app.on('error', (err) => {
// handle error
})
Application
extends
: The application interface.events.EventEmitter
Name | Type & Description | Initial |
---|---|---|
constructor | new (options?: ApplicationOptions) => Application | |
Creates a new app instance. | ||
proxy | boolean | false |
Whether the server is running behind a proxy. | ||
middleware | !Array<!Middleware> | [] |
The array with middleware used on the server. | ||
context | !Context | - |
The context object for each request. | ||
request | !Request | - |
The request object for each request. | ||
response | !Response | - |
The response object for each request. | ||
env | string | development |
The value from the NODE_ENV environment variable.
|
||
keys | !(Keygrip | Array<string>) | - |
The keys for signing of the cookies. | ||
silent | boolean | false |
Whether to not log an error when it happens. | ||
subdomainOffset | number | 2 |
For example, if the domain is tobi.ferrets.example.com:
app.subdomainOffset is not set, request.subdomains is ["ferrets", "tobi"] .app.subdomainOffset is 3, request.subdomains is ["tobi"] . |
||
listen | (...args: *[]) => ![]() |
|
Shorthand for: http.createServer(app.callback()).listen(...) .
|
||
use | (middleware: !Middleware) => !Application | |
Use the given middleware fn . Old-style middleware will be converted.
|
||
callback | () => function(![]() ![]() |
|
Returns the request handler callback for Node's native http/http2 server composed of the installed middleware. | ||
createContext | (req: ![]() ![]() |
|
@private Initialize a new context.
|
||
onerror | (error: !Error) => ? | |
@private Default error handler.
|
||
toJSON | () => !Object | |
Return JSON representation. | ||
inspect | () => !Object | |
util.inspect() implementation, which just returns the JSON output.
|
ApplicationOptions
: Options for the application constructor.
Name | Type & Description | Default |
---|---|---|
proxy | boolean | false |
Whether the app should start in a proxy mode. | ||
subdomainOffset | number | 2 |
The offset for subdomains. | ||
env | string | - |
App environment. The default is process.env.NODE_ENV || 'development' .
|
||
keys | !(Keygrip | Array<string>) | - |
The keys for cookies, or a Keygrip instance. | ||
Context | new () => Context | |
The custom context constructor. |
The function to handle requests which can be installed with the .use
method.
-
ctx*
!Context
: The context. -
next
!Function
(optional): The callback.