'created smparkinVaporWeb from template https://github.com/vapor/web-template'

This commit is contained in:
Stephen
2019-10-31 16:50:33 -07:00
commit 931b897f65
22 changed files with 436 additions and 0 deletions

View File

View File

12
Sources/App/app.swift Normal file
View File

@@ -0,0 +1,12 @@
import Vapor
/// Creates an instance of `Application`. This is called from `main.swift` in the run target.
public func app(_ env: Environment) throws -> Application {
var config = Config.default()
var env = env
var services = Services.default()
try configure(&config, &env, &services)
let app = try Application(config: config, environment: env, services: services)
try boot(app)
return app
}

6
Sources/App/boot.swift Normal file
View File

@@ -0,0 +1,6 @@
import Vapor
/// Called after your application has initialized.
public func boot(_ app: Application) throws {
// Your code here
}

View File

@@ -0,0 +1,22 @@
import Leaf
import Vapor
/// Called before your application initializes.
public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
// Register providers first
try services.register(LeafProvider())
// Register routes to the router
let router = EngineRouter.default()
try routes(router)
services.register(router, as: Router.self)
// Use Leaf for rendering views
config.prefer(LeafRenderer.self, for: ViewRenderer.self)
// Register middleware
var middlewares = MiddlewareConfig() // Create _empty_ middleware config
middlewares.use(FileMiddleware.self) // Serves files from `Public/` directory
middlewares.use(ErrorMiddleware.self) // Catches errors and converts to HTTP response
services.register(middlewares)
}

16
Sources/App/routes.swift Normal file
View File

@@ -0,0 +1,16 @@
import Vapor
/// Register your application's routes here.
public func routes(_ router: Router) throws {
// "It works" page
router.get { req in
return try req.view().render("welcome")
}
// Says hello
router.get("hello", String.parameter) { req -> Future<View> in
return try req.view().render("hello", [
"name": req.parameters.next(String.self)
])
}
}