Skip to content

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 Node.JS Docsevents.EventEmitter: The application interface.

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:
  • if app.subdomainOffset is not set, request.subdomains is ["ferrets", "tobi"].
  • if app.subdomainOffset is 3, request.subdomains is ["tobi"].
  • listen (...args: *[]) => Node.JS Docs!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(Node.JS Docs!http.IncomingMessage, Node.JS Docs!http.ServerResponse)
    Returns the request handler callback for Node's native http/http2 server composed of the installed middleware.
    createContext (req: Node.JS Docs!http.IncomingMessage, res: Node.JS Docs!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.
    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.

    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