'created smparkinVaporWeb from template https://github.com/vapor/web-template'
This commit is contained in:
0
Sources/App/Controllers/.gitkeep
Normal file
0
Sources/App/Controllers/.gitkeep
Normal file
0
Sources/App/Models/.gitkeep
Normal file
0
Sources/App/Models/.gitkeep
Normal file
12
Sources/App/app.swift
Normal file
12
Sources/App/app.swift
Normal 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
6
Sources/App/boot.swift
Normal file
@@ -0,0 +1,6 @@
|
||||
import Vapor
|
||||
|
||||
/// Called after your application has initialized.
|
||||
public func boot(_ app: Application) throws {
|
||||
// Your code here
|
||||
}
|
||||
22
Sources/App/configure.swift
Normal file
22
Sources/App/configure.swift
Normal 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
16
Sources/App/routes.swift
Normal 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)
|
||||
])
|
||||
}
|
||||
}
|
||||
3
Sources/Run/main.swift
Normal file
3
Sources/Run/main.swift
Normal file
@@ -0,0 +1,3 @@
|
||||
import App
|
||||
|
||||
try app(.detect()).run()
|
||||
Reference in New Issue
Block a user