These docs are for v0.12. Click to read the latest docs for v0.16.

Application

The Application is a core class that gives you access to many of Vapor's facilities. It is responsible for registering routes, starting the server, appending middleware, and more.

Initialization

As you have probably already seen, the only thing required to create an instance of Application is to import Vapor.

import Vapor

let app = Application()

// your magic here

app.start()

Creation of the Application normally happens in the main.swift file.

Environment

This contains the current environment your application is running in. Usually development, testing, or production.

if app.config.environment == .production {
    ...
}

Learn more about how to configure and use Environment in the Environment section of this guide.

Working Directory

This property contains a path to the current working directory of the application relative to where it was started. By default, this property assumes you started the application from its root directory.

app.workDir = "/var/www/my-project/"

You can change the working directory programmatically, or override the default when executing.

vapor run --workDir="/var/www/my-project"

Resources Directory

The resources directory is a read only property that builds the path for the Resources directory from the Working Directory.

print(app.resourcesDir)

Customization

The application has several customizable properties.

Most plugins for Vapor come with a Provider, these take care of configuration details for you. Read more about providers in the Providers section.

Application(
    workDir: String? = nil,
    config: Config? = nil,
    localization: Localization? = nil,
    hash: HashDriver? = nil,
    console: ConsoleDriver? = nil,
    server: ServerDriver.Type? = nil,
    router: RouterDriver? = nil,
    session: SessionDriver? = nil,
    providers: [Provider] = [],
    arguments: [String]? = nil
)