As mentioned earlier, the app object used in main.swift is actually created in the constructor function declared in app.swift:
// File: /Sources/App/app.swift
import Vapor
/// Creates an instance of Application. This is called from main.swift in the run target.
public func app(_ : Environment) throws -> Application { // [1]
var config = Config.default() // [2]
var env = env
var services = Services.default() // [3]
try configure(&config, &env, &services) // [4]
let app = try Application(: config, : env, : services) // [5]
try boot(app) // [6]
return app
}
The preceding code sets up the sequence of calling several functions:
- The app() constructor takes in the environment as a passing-in parameter
- The config variable is assigned to the default configuration
- The services variable is assigned to the default services...