{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","results":{"codes":[]},"settings":"","params":[]},"next":{"description":"","pages":[]},"title":"Application","type":"basic","slug":"application","excerpt":"","body":"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.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Initialization\"\n}\n[/block]\nAs you have probably already seen, the only thing required to create an instance of `Application` is to import Vapor.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"import Vapor\\n\\nlet app = Application()\\n\\n// your magic here\\n\\napp.start()\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\nCreation of the `Application` normally happens in the `main.swift` file. \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Environment\"\n}\n[/block]\nThis contains the current environment your application is running in. Usually development, testing, or production.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"if app.config.environment == .production {\\n    ...\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\nLearn more about how to configure and use Environment in the Environment section of this guide.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Working Directory\"\n}\n[/block]\nThis 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. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"app.workDir = \\\"/var/www/my-project/\\\"\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\nYou can change the working directory programmatically, or override the default when executing.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"vapor run --workDir=\\\"/var/www/my-project\\\"\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Resources Directory\"\n}\n[/block]\nThe resources directory is a read only property that builds the path for the Resources directory from the Working Directory.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"print(app.resourcesDir)\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Customization\"\n}\n[/block]\nThe application has several customizable properties.\n\nMost plugins for Vapor come with a `Provider`, these take care of configuration details for you. Read more about providers in the Providers section.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Application(\\n    workDir: String? = nil,\\n    config: Config? = nil,\\n    localization: Localization? = nil,\\n    hash: HashDriver? = nil,\\n    console: ConsoleDriver? = nil,\\n    server: ServerDriver.Type? = nil,\\n    router: RouterDriver? = nil,\\n    session: SessionDriver? = nil,\\n    providers: [Provider] = [],\\n    arguments: [String]? = nil\\n)\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]","updates":["570f29edd6c6f00e00b98709","5736f6e01a48812200566f23"],"order":1,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"5768701b72cd4c0e000fad1e","version":{"version":"0.12","version_clean":"0.12.0","codename":"Client Clyde","is_stable":false,"is_beta":true,"is_hidden":false,"is_deprecated":true,"categories":["5768701b72cd4c0e000fad19","5768701b72cd4c0e000fad1a","5768701b72cd4c0e000fad1b","5768701b72cd4c0e000fad1c"],"_id":"5768701b72cd4c0e000fad18","releaseDate":"2016-06-20T22:37:15.641Z","__v":1,"createdAt":"2016-06-20T22:37:15.641Z","project":"57086fe855a4690e005de407"},"category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Guide","slug":"getting-started","order":1,"from_sync":false,"reference":false,"_id":"5768701b72cd4c0e000fad1a","createdAt":"2016-04-09T04:31:52.489Z","__v":0,"version":"5768701b72cd4c0e000fad18","project":"57086fe855a4690e005de407"},"createdAt":"2016-04-09T19:18:15.036Z","githubsync":"","parentDoc":null,"user":"57086f3d447c410e00221bd1","__v":0,"project":"57086fe855a4690e005de407"}
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. [block:api-header] { "type": "basic", "title": "Initialization" } [/block] As you have probably already seen, the only thing required to create an instance of `Application` is to import Vapor. [block:code] { "codes": [ { "code": "import Vapor\n\nlet app = Application()\n\n// your magic here\n\napp.start()", "language": "swift" } ] } [/block] Creation of the `Application` normally happens in the `main.swift` file. [block:api-header] { "type": "basic", "title": "Environment" } [/block] This contains the current environment your application is running in. Usually development, testing, or production. [block:code] { "codes": [ { "code": "if app.config.environment == .production {\n ...\n}", "language": "swift" } ] } [/block] Learn more about how to configure and use Environment in the Environment section of this guide. [block:api-header] { "type": "basic", "title": "Working Directory" } [/block] 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. [block:code] { "codes": [ { "code": "app.workDir = \"/var/www/my-project/\"", "language": "swift" } ] } [/block] You can change the working directory programmatically, or override the default when executing. [block:code] { "codes": [ { "code": "vapor run --workDir=\"/var/www/my-project\"", "language": "shell" } ] } [/block] [block:api-header] { "type": "basic", "title": "Resources Directory" } [/block] The resources directory is a read only property that builds the path for the Resources directory from the Working Directory. [block:code] { "codes": [ { "code": "print(app.resourcesDir)", "language": "swift" } ] } [/block] [block:api-header] { "type": "basic", "title": "Customization" } [/block] 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. [block:code] { "codes": [ { "code": "Application(\n workDir: String? = nil,\n config: Config? = nil,\n localization: Localization? = nil,\n hash: HashDriver? = nil,\n console: ConsoleDriver? = nil,\n server: ServerDriver.Type? = nil,\n router: RouterDriver? = nil,\n session: SessionDriver? = nil,\n providers: [Provider] = [],\n arguments: [String]? = nil\n)", "language": "swift" } ] } [/block]