Refactor for flask
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
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
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
import Vapor
|
||||
|
||||
// Called after your application has initialized.
|
||||
public func boot(_ app: Application) throws {
|
||||
// Your code here
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import Leaf
|
||||
import Vapor
|
||||
|
||||
// Called before your application initializes.
|
||||
public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
|
||||
// Register routes to the router
|
||||
let router = EngineRouter.default()
|
||||
try routes(router)
|
||||
services.register(router, as: Router.self)
|
||||
|
||||
//leaf
|
||||
try services.register(LeafProvider())
|
||||
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)
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import Vapor
|
||||
|
||||
// Register your application's routes here.
|
||||
public func routes(_ router: Router) throws {
|
||||
router.get("") { request in
|
||||
return try request.view().render("home")
|
||||
}
|
||||
router.get("index.html") { request in
|
||||
return try request.view().render("home")
|
||||
}
|
||||
router.get("privacy") { request in
|
||||
return try request.view().render("privacy")
|
||||
}
|
||||
router.get("404") { request in
|
||||
return try request.view().render("404")
|
||||
}
|
||||
router.get("welcome") { request in
|
||||
return try request.view().render("welcome")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user