Skip to content

Application

Anton edited this page Dec 19, 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 events.EventEmitter: The application interface.

Name Type & Description Initial
constructor new () => Application
Constructor method.
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 -
For example, if the domain is "tobi.ferrets.example.com": If app.subdomainOffset is not set, request.subdomains is ["ferrets", "tobi"]. If app.subdomainOffset is 3, request.subdomains is ["tobi"].
listen (...args: *[]) => !http.Server
Shorthand for: http.createServer(app.callback()).listen(...).
use (middleware: !Middleware) => !Application
Use the given middleware fn. Old-style middleware will be converted.
callback () => function(!http.IncomingMessage, !http.ServerResponse)
Returns the request handler callback for node's native http/http2 server composed of the installed middleware.
createContext (req: !http.IncomingMessage, res: !http.ServerResponse) => !Context
@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.

Middleware(
  ctx: !Context,
  next=: !Function,
): (!Promise|void)

The function to handle requests which can be installed with the .use method.

  • ctx* !Context: The context.
  • next !Function (optional): The callback.
Clone this wiki locally